conditionals in macros concatenating 2 files to a third

conditionals in macros concatenating 2 files to a third

2
NewbieNewbie
2

    Jan 03, 2008#1

    happy new year everyone!

    i spent my free time between christmas and new year trying to figure the following on ultraedit 12.10:

    read block numbers from french subtitle file f.srt with incorrect timestamps
    read timestamps from english subtitle file e.srt with correct timestamps
    read french subtitles from f.srt
    write all these into corrected file c.srt
    there are either one or two lines of text per block and there aren't necessarily equal numbers of subtitle lines between french and english files. the original files had a CR (dec 13) between each block. there is over 300 blocks per file so doing it by hand gets excruciatingly tedious.

    for example:

    "f.srt" =

    "
    1
    00:02:09,320 --> 00:02:11,197
    Papa arrive.

    2
    00:02:13,280 --> 00:02:15,430
    Ricane pas, tu vas tout gâcher.

    3
    00:02:15,640 --> 00:02:18,950
    Il doit pas savoir que maman a payé
    2 500 $ pour un portrait d'elle.

    4
    00:02:20,440 --> 00:02:22,749
    Vraiment. Arrête.

    5
    00:02:26,480 --> 00:02:29,472
    Bien. T'as laissé le prix dessus ?

    6
    00:02:29,680 --> 00:02:34,037
    Non, vraiment, arrête.
    Ça pourrait le tuer, tu sais.

    7
    00:02:36,200 --> 00:02:39,397
    Attends. Bud, on n'a pas
    une dette envers lui ?

    "

    AND

    "e.srt" =

    "
    1
    00:01:21,331 --> 00:01:23,250
    Dad's coming. Dad's coming.

    2
    00:01:25,460 --> 00:01:27,671
    Don't giggle. You'll give it away.

    3
    00:01:27,921 --> 00:01:31,341
    He's not to know Mom commissioned
    a painting of herself for $2500.

    4
    00:01:32,926 --> 00:01:35,304
    Really. Don't.

    5
    00:01:39,224 --> 00:01:42,311
    Okay, okay.
    Did you leave the price tag on?

    6
    00:01:42,561 --> 00:01:47,065
    No, really, really, don't.
    This could kill him, you know.

    7
    00:01:49,359 --> 00:01:52,654
    Wait. Bud, don't we have
    a loyalty to the man?

    "
    SHOULD GIVE:

    "c.srt" =

    "
    1
    00:01:21,331 --> 00:01:23,250
    Papa arrive.

    2
    00:01:25,460 --> 00:01:27,671
    Ricane pas, tu vas tout gâcher.

    3
    00:01:27,921 --> 00:01:31,341
    Il doit pas savoir que maman a payé
    2 500 $ pour un portrait d'elle.

    4
    00:01:32,926 --> 00:01:35,304
    Vraiment. Arrête.

    5
    00:01:39,224 --> 00:01:42,311
    Bien. T'as laissé le prix dessus ?

    6
    00:01:42,561 --> 00:01:47,065
    Non, vraiment, arrête.
    Ça pourrait le tuer, tu sais.

    7
    00:01:49,359 --> 00:01:52,654
    Attends. Bud, on n'a pas
    une dette envers lui ?


    with french file opened in the first tab, the english in the second and the corrected file starting empty in the third tab
    the macro i came up with:

    InsertMode
    ColumnModeOff
    HexOff
    UnixReOff
    Loop
    SelectLine
    Copy
    NextDocument
    Key DOWN ARROW
    NextDocument
    Paste
    NextDocument
    Key DOWN ARROW
    NextDocument
    SelectLine
    Copy
    Key DOWN ARROW
    NextDocument
    Paste
    NextDocument
    SelectLine
    Copy
    NextDocument
    NextDocument
    Paste
    NextDocument
    IfCharIs 13
    Key DOWN ARROW
    NextDocument
    NextDocument
    "
    "
    NextDocument
    Else
    SelectLine
    Copy
    Key DOWN ARROW
    NextDocument
    NextDocument
    Paste
    "
    "
    NextDocument
    EndIf
    NextDocument
    IfCharIs 13
    Key DOWN ARROW
    NextDocument
    NextDocument
    Else
    Key DOWN ARROW
    Key DOWN ARROW
    NextDocument
    NextDocument
    EndIf
    EndLoop

    works ok until half of the second block and since there seems to be no way to do a step by step execution of the macro, i have a hard time figuring where the behavior of the "if else" in it diverges from my expectations. not to mention that i tried a few places for the end of file test without any good results either. my coding experience dates back to fortran 25 years ago and it seemed a bit more explicit and had a larger instruction set than what is available in ultraedit but i believe it is possible to solve this with ultraedit, it's likely just that i don't have a deep enough feel or time to cinch it.

    can anyone tell me how to fix this macro?
    any help will be appreciated.

    :)

    6,686585
    Grand MasterGrand Master
    6,686585

      Jan 03, 2008#2

      I have not run and deeply investigated what your macro does. Maybe IfCharIs fails because of existing selection.

      However, I think I have a much faster solution. You must have only the 2 files "f.srt" and "e.srt" open and "f.srt" must have the focus.

      The macro first selects complete content of "f.srt", copies it to a new file and sets the cursor in both files to top of the file. Next it switches to file "e.srt" and sets the cursor also in this file to top of the file.

      Now the loop follows. Inside the loop a regular expression search in UltraEdit syntax is used to find and select complete line with the time tag without the line ending character(s). If a time tag line is not found anymore, the loop will be breaked. Otherwise the found line without the line ending is copied to user clipboard 9 and the cursor is move to next line in file "e.srt".

      Next the window is switched back to the new file where with the same regular expression search the next wrong time tag line is replaced with the correct time tag from "e.srt" in user clipboard 9. For security I have added also here a loop exit if in the new file there was no time tag line to replace anymore.

      If everything works correct (= number of time tag lines in both source files is equal), the new file should have the focus after macro execution with cursor at end of last time tag line.

      The macro property Continue if a Find with Replace not found must be checked for this macro.

      InsertMode
      ColumnModeOff
      HexOff
      UnixReOff
      SelectAll
      Clipboard 9
      Copy
      EndSelect
      Top
      NewFile
      Paste
      Top
      PreviousWindow
      Top
      Loop
      Find RegExp "%[0-2][0-9]:[0-5][0-9]:[0-5][0-9],[0-9][0-9][0-9]*$"
      IfNotFound
      NextWindow
      ExitLoop
      EndIf
      Copy
      EndSelect
      Key DOWN ARROW
      NextWindow
      Find RegExp "%[0-2][0-9]:[0-5][0-9]:[0-5][0-9],[0-9][0-9][0-9]*$"
      Replace "^c"
      IfNotFound
      ExitLoop
      EndIf
      PreviousWindow
      EndLoop
      ClearClipboard
      Clipboard 0
      Best regards from an UC/UE/UES for Windows user from Austria

      2
      NewbieNewbie
      2

        Jan 04, 2008#3

        Mofi, you are a beautiful ultraedit person of 2008!
        i will study how you did it because it is an elegant solution
        that works both fast and accurately in the tests i ran tonight.
        thank you very much from the bottom of my neurons.
        and less than a day later!!

        :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-)