Topic: Vedit6.0+ Sort macro; by size? (1 of 11), Read 72 times
Conf: VEDIT Macro Library
From: Peter Rejto
Date: Thursday, October 11, 2001 03:59 PM

Hi,

I would like to sort a file also according to size. Is this possible by a clever choice of the sorting table?

Thanks,

-peter.

 


Topic: Re: Vedit6.0+ Sort macro; by size? (2 of 11), Read 65 times
Conf: VEDIT Macro Library
From: Ted Green
Date: Thursday, October 11, 2001 05:04 PM

At 03:59 PM 10/11/2001, you wrote:
>I would like to sort a file also according to size. Is this possible by a clever choice of the sorting table?

I assume you mean to sort by line length ??

This might be possible with a special collate table which contains only one line to equate all characters (0x21-0x7e) to the same value.

Ted.

 


Topic: Re: Vedit6.0+ Sort macro; by size? (3 of 11), Read 61 times
Conf: VEDIT Macro Library
From: Christian Ziemski
Date: Friday, October 12, 2001 09:35 AM

>I'm not Peter, but reading this i felt like an undergrad
>student who has been assigned his final
>semester test. So, please let me pass... :
>
>BOF
>while(!at_eof){
>EOL()
>#1=CurPos()
>BOL()
>#2=CurPos()
>numins(#1-#2,nocr)
>instext(" ")
>line()
>}

Yes, good. But not perfect. ;-))

- the line length could be determined easier
- the inserted numbers should be padded with
leading zero's to make the sort work
correct.

To be continued...

Christian

 


Topic: Re: Vedit6.0+ Sort macro; by size? (4 of 11), Read 61 times
Conf: VEDIT Macro Library
From: Fritz Heberlein
Date: Friday, October 12, 2001 09:56 AM

> Yes, good. But not perfect. ;-))
>
> - the line length could be determined easier
> - the inserted numbers should be padded with
> leading zero's to make the sort work
> correct.

Thank you, Professor Ziemski,
for correcting my semester test so quickly.
May i submit my improved version:

BOF
while(!at_eof){
EOL()
#1=CurCol()
BOL()
numins(#1,nocr+fill)
instext(" ")
line()
}

Respectfully,
your humble student

Fritz

 


Topic: Re: Vedit6.0+ Sort macro; by size? (5 of 11), Read 62 times
Conf: VEDIT Macro Library
From: Christian Ziemski
Date: Friday, October 12, 2001 10:25 AM

>BOF
>while(!at_eof){
>EOL()
>#1=CurCol()
>BOL()
>numins(#1,nocr+fill)
>instext(" ")
>line()
>}

Very good, student Fritz!
It's working as expected, but the line length is calculated one too high.

And now the extension:
- how to sort the file now? and
- how to remove the inserted numbers again?

If you can solve this too, you'll get a "1+" or "A"!

Your professor.

 


Topic: Re: Vedit6.0+ Sort macro; by size? (6 of 11), Read 63 times
Conf: VEDIT Macro Library
From: Fritz Heberlein
Date: Friday, October 12, 2001 10:40 AM

> It's working as expected, but the line length is calculated one too
> high.
>
> And now the extension:
> - how to sort the file now? and
> - how to remove the inserted numbers again?
>
Well, just a quick try (i have a class at 5pm):

BOF()
sort_merge("1,6",0,file_size)
BOF()
while(!at_eof){
BOL()
delchar(6)
line()
}

If this works, too, Peter will have to take out us for a beer.
Fritz

 


Topic: Re: Vedit6.0+ Sort macro; by size? (7 of 11), Read 62 times
Conf: VEDIT Macro Library
From: Ted Green
Date: Friday, October 12, 2001 03:25 PM

At 10:40 AM 10/12/2001, you wrote:
>If this works, too, Peter will have to take out us for a beer.

Peter is on a flight to Germany right now. He looks forward to taking you out to dinner, and then going beer (bar) hopping. ;-))

 


Topic: Re: Vedit6.0+ Sort macro; by size? (8 of 11), Read 62 times
Conf: VEDIT Macro Library
From: Christian Ziemski
Date: Friday, October 12, 2001 04:36 PM

>BOF()
>sort_merge("1,6",0,file_size)
>BOF()
>while(!at_eof){
>BOL()
>delchar(6)
>line()
>}
>
>If this works, too, Peter will have to take out us for a beer.


Peter, two beer please! :-)


Christian - no longer a professor now

 


Topic: Re: Vedit6.0+ Sort macro; by size? (9 of 11), Read 63 times
Conf: VEDIT Macro Library
From: Ted Green
Date: Friday, October 12, 2001 05:13 PM

At 04:36 PM 10/12/2001, you wrote:
>numins(#1-#2,nocr)
>...
>>delchar(6)

This will only work with files of up to 65,535 lines. After that
Num_Ins will generate 10 digit positive numbers.

Therefore, it would be better to use:

Num_Ins(#1-#2,nocr+force) //Force 10 digit numbers
....
Del_Char(11)

Thank you for all your work on this. I will add it to VEDIT soon.

Ted.

 


Topic: Re: Vedit6.0+ Sort macro; by size? (10 of 11), Read 60 times
Conf: VEDIT Macro Library
From: Peter Rejto
Date: Friday, October 12, 2001 10:41 PM

Thanks Christian and Fritz,

I have spent many wonderful Sabbaticals in Germany. Looking forward to taking both of you out for a double beer on my next Sabbatical.

Cheers,

-peter.

 


Topic: Re: Vedit6.0+ Sort macro; by size? (11 of 11), Read 70 times, 2 File Attachments
Conf: VEDIT Macro Library
From: Christian Ziemski
Date: Saturday, October 13, 2001 03:00 AM

Here the complete macro (a bit optimized and documented):

Since the HTML converter of WebBoard reformats the macro I attached it as file too.


//
// SORTLENGTH.VDM F.Heberlein and Ch.Ziemski 12.10.2001
// last change 13.10.2001
//
// Sorts a file by line length
//

Num_Push(1,1) // save the used register

BOF
while(!At_Eof){ //
EOL() //
#1=Cur_Col()-1 // get length of every line
BOL() //
Num_Ins(#1, NOCR+FILL+FORCE) // and write it as 10 digit number at line begin
Ins_Text(" ") //
Line(1, NOERR) // handle possible last line without CR/LF too
}

Num_Pop(1,1) // restore the used register


Sort_Merge("1,11", 0, File_Size) // sort the whole text (by the leading number)


// BOF()
// while(!At_Eof){ //
// BOL() //
// Del_Char(11) // remove the numbers again
// Line(1)
// }

// or shorter (and faster for big files):

End_Of_File
Line(-1)
Del_Block(0, Cur_Pos+11, COLUMN) // remove the numbers again



Christian

 
SORTLENGTH.VDM (1KB)
 
SORTLENGTH(1).VDM (1KB)