Reverse order of chat log from most recent at top to MR at bottom

Home Forums Multi-Edit User Created Macros Reverse order of chat log from most recent at top to MR at bottom

This topic contains 18 replies, has 3 voices, and was last updated by  Clay Martin 1 week, 2 days ago.

Viewing 15 posts - 1 through 15 (of 19 total)
  • Author
    Posts
  • #24749

    CharlesG
    Participant

    I have a chat log from another website where the most recent appears at the top and not at the bottom, where I would like it to be. Each conversation is delimited by the result of

    ==================================================================================================

    and a black line both before and after that.

    Any help with the simple macro would be helpful and be greatful.

    TIA,
    Charles.

    #24750

    Clay Martin
    Keymaster

    Hi,
    The only way I can think of doing this is to open a second file. Then read an entry, write (insert) it into the new file, then do a TOF and repeat with the next entry.

    Clay

    #24752

    CharlesG
    Participant

    Guess this board doesn’t allow uploading TXT files to use as an example?

    #24754

    Clay Martin
    Keymaster

    Nope, that sucks but you can cut and paste.

    Think it would go like this
    Loop until eof source
    a= line number
    search forward till “======”
    b = line number
    Copy a to b
    down
    switch to new file
    write copied block
    tof
    switch to source file
    end of loop.

    #24755

    CharlesG
    Participant

    I saw I can post a link here so I uploaded before.txt and after.txt to the Mew folder on my OneDrive.

    My sample Text Files

    Is the link

    #24758

    rohitch71
    Participant

    Yes, I’ve seen this (however why they cannot be sorted by time?). The problem that the component doesn’t scroll to bottom after load to show last (bottom) message.

    Visit here for more information

    #24760

    CharlesG
    Participant

    @rohitch71 Because it is sorted by time. Just more recent at the top and I would like MR at the bottom. And what component are you referring to?

    #24762

    Clay Martin
    Keymaster

    Hi,
    I think this will do it. Not sure about formatting of RM command. No file existing or error processing either.

    int sourcef = Window_id();
    str targetfn=”/name.txt”;
    RM(“ld_files(/lc=1,/FN=”+targetfn+” )”);
    int targetf = Window_id();
    Switch_window(sourcef) ;
    TOF;
    do
    Block_begin();
    search_fwd(“====”, 0);
    Block_end();
    Swich_window(targetf);
    Window_copy(sourcef) ;
    TOF;
    Swich_window(sourcef);
    down;
    while(not EOF);

    // close stuff up

    • This reply was modified 3 weeks, 1 day ago by  Clay Martin.
    #24764

    CharlesG
    Participant

    Thank you Clay! It might be a few days before I look into this more as my mother thinks she had a mild stroke a few days ago.

    I’d like to have the target filename be:

    source = susan_all.txt
    becomes
    target = susan_all_new.txt

    but not sure how to insert the “_new” before the period and extension of source name

    =======

    I’d like to have the search be for “%” + repeat[98,=] + “$”;

    =====

    would I need to check the value of Insert key?

    ======

    would I need to check that the RegExpType is set to Classic – just for saftys sake?

    #24766

    Clay Martin
    Keymaster

    With some corections

    int sourcef = Window_id();
    str sourcefn = FILE_NAME;
    int slen = LENGTH(sourcefn) – 3;
    str targetfn = STR_DEL(sourcefn,SLEN,4) + “_new” + “.txt”;
    RM(“ld_files(/lc=1,/FN=”+targetfn+” )”);
    int targetf = Window_id();
    Switch_window(sourcef) ;
    TOF;
    do
    Block_begin();
    search_fwd(“====”, 0);
    Block_end();
    Swich_window(targetf);
    Window_copy(sourcef) ;
    TOF;
    Swich_window(sourcef);
    down;
    while(not EOF);

    // close stuff up

    The search I have provided will find the separator line. If you feel you must use a regexp, use
    Find_Text( “%” + “=+” + “$”, 0, _OldExp); //begin line, one or more =, end of line
    I don’t think with a window_copy you need to worry about insert. _OldExp will make sure it is classic not unix.

    #24767

    CharlesG
    Participant

    Thank you. I changed it into a Macro file and into a macro and uploaded FormetEH.s to my OneDrive folder. I’m getting an error and can’t tell where it is….

    OneDrive: https://1drv.ms/f/s!Ap7yFWW-HrgenXu20jeycnnk_2gC

    Have a great Labor Day weekend!

    #24768

    Clay Martin
    Keymaster

    Hi,
    Usually macros begin like this
    int LisAgree( ) trans2
    or
    macro LdFiles trans2
    Usually you want to keep macro in memory for your session.

    Made a few changes to get a clean compile (long time since I worked with CMac) Here is an updated version that worked against your test data.

    macro FormatEH trans2

    {
    str cSrch = “%=*$”;
    int sourcef = Window_id();
    str sourcefn = FILE_NAME;
    int slen = LENGTH(sourcefn) – 3;
    str targetfn = STR_DEL(sourcefn,SLEN,4) + “_new” + “.txt”;
    Rm( “LdFiles /LC=1/FN=” + targetfn );
    int targetf = Window_id();
    Switch_window(sourcef);
    TOF;
    do {
    rm(“MarkBlck”);
    Find_Text( cSrch, 0, _OldExp );
    Block_end;
    Switch_window(targetf);
    Window_copy(sourcef);
    TOF;
    Switch_window(sourcef);
    down;
    } while ( ! At_EOF );
    } // FormatEH

    #24769

    CharlesG
    Participant

    Hope you had a very great Labor day weekend Clay! Mine was okay.

    About the Mew Macro:
    1) the compile bug seems to be with the first line
    below, which I would prefer to correct then use
    your very short one. It should be just start of
    line, then 98 of “=” then end of line.

    str cSrch = “%==================================================================================================$”;
    str cSrch = “%=*$”;

    2) Any lines before the separation line described
    above, is the preface and should be copied verbatim
    to the top of the targetfn window.

    thamk you very very much!

    #24770

    CharlesG
    Participant

    Clay,
    I have uploaded the FormatEH.s and Susan_all.txt to the onedrive link given above. the .S file is slightly modified to I think handle the preface – if it does exist, as in the susan_all.txt.

    OneDrive: https://1drv.ms/f/s!Ap7yFWW-HrgenXu20jeycnnk_2gC

    Thank you for your help in helping me with this somewhat simple macro.

    Charles.

    #24772

    Clay Martin
    Keymaster

    Charles,
    The error on your original (with all the =) line was that you had Word “smart quotes” instead of ASCII “.

    This will take care of the “header”

    macro FormatEH trans2

    {
    str cSrch = “%=*$”;
    int headerstop;
    int sourcef = Window_id();
    str sourcefn = FILE_NAME;
    int slen = LENGTH(sourcefn) – 3;
    str targetfn = STR_DEL(sourcefn,SLEN,4) + “_new” + “.txt”;
    Rm( “LdFiles /LC=1/FN=” + targetfn );
    int targetf = Window_id();
    Switch_window(sourcef);
    TOF;
    rm(“MarkBlck”);
    Find_Text( cSrch, 0, _OldExp );
    Block_end;
    Switch_window(targetf);
    Window_copy(sourcef);
    Down;
    headerstop= C_line;
    Switch_window(sourcef);
    Down;

    do {
    rm(“MarkBlck”);
    Find_Text( cSrch, 0, _OldExp );
    Block_end;
    Switch_window(targetf);
    Window_copy(sourcef);
    Goto_Line( headerstop );
    Switch_window(sourcef);
    down;
    } while ( ! At_EOF );
    } // FormatEH

Viewing 15 posts - 1 through 15 (of 19 total)

You must be logged in to reply to this topic.