Content Plugin that shows line break style/type?

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
User avatar
Dalai
Power Member
Power Member
Posts: 9389
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Content Plugin that shows line break style/type?

Post by *Dalai »

Hi there.

Yesterday, I came across a Linux script file that had Windows line breaks by mistake. When this happened I wanted to check if any of my other scripts had the same thing. Yes, I can search for

Code: Select all

0D 0A
in Find Files' Hex mode. But I'd like to have the type of line break in a custom column.

Is there a Content Plugin which can provide a field that returns something like LF, CRLF, None, Others/Binary or similar? I think I vaguely remember having seen topics in this forum, but apparently I'm missing the right search terms to find these threads. Sure, I could write such a plugin myself, but I wouldn't have to if someone else has already done it :).

Regards
Dalai
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
User avatar
beb
Senior Member
Senior Member
Posts: 435
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

Re: Content Plugin that shows line break style/type?

Post by *beb »

may this one fit your needs:

wdx_PCREsearch
https://ghisler.ch/board/viewtopic.php?t=38098

Line breaks to search:
\x0d\x0a :: Windows
\x0a :: Unix
\x0d :: Mac
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10
User avatar
beb
Senior Member
Senior Member
Posts: 435
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

Re: Content Plugin that shows line break style/type?

Post by *beb »

Tested it a bit on a primitive level [bare plugin as it comes in its archive; no other libraries included/installed; the simplest regex queries], and it looks as though it could do the task to a certain extent somehow:
In my simple example, the plugin just counts line break entries in three test files of Mac, Unix, and Win formats:
Image: https://i.imgur.com/5cgO1cr.png

Edit:
A bit more cpecific queries {regex1=\x0d(?!\x0a), regex2=(?<!\x0d)\x0a, regex3=\x0d\x0a} that, in fact, identify the line break's style in the example files unambiguously:

PCREsearch.ini

Code: Select all

; for reference:
; \r   :: \x0d     :: Mac
; \n   :: \x0a     :: Unix
; \r\n :: \x0d\x0a :: Windows

; PCREsearch.ini
[PCREsearch]
regexcount=3
regex1=\x0d(?!\x0a)
regex2=(?<!\x0d)\x0a
regex3=\x0d\x0a

regex1name=Mac
regex2name=Unix
regex3name=Win

regex1type=1
regex2type=1
regex3type=1
TC .ini custom columns

Code: Select all

[CustomFields]
Titles=test line breaks
Headers1=Mac :: r\nUnix :: n\nWin :: rn
Contents1=[=pcresearch.Mac]\n[=pcresearch.Unix]\n[=pcresearch.Win]
Visual result (within the example approach):
Image: https://i.imgur.com/PE06kJw.png

edit 2:
At a glance, wdx_PCREsearch has pretty much more advanced configurable options than that I used in the example, so I dare to assume it''s worth further studying regarding your request with a reasonable hope to succeed.
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10
User avatar
Dalai
Power Member
Power Member
Posts: 9389
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Re: Content Plugin that shows line break style/type?

Post by *Dalai »

Well, I had hoped there's a plugin that provides a multiple choice field returning the kind of line break.

Regards
Dalai
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
User avatar
beb
Senior Member
Senior Member
Posts: 435
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

Re: Content Plugin that shows line break style/type?

Post by *beb »

Dalai wrote: 2023-10-31, 23:49 UTC ...plugin that provides a multiple choice field returning the kind of line break.
Technically, it appears, wdx_PCREsearch provides exactly what is being requested.

With the following approach, you are getting a single column for the line breaks style output in a simple literal form (that is of course customizable):
(where "regex1=\x0d(?!\x0a)", "regex2=(?<!\x0d)\x0a", "regex3=\x0d\x0a" illustrate multiple choice, that as a bonus is user defined within regex syntax and not limited by a hypothetical other plugin author's vision and choice)

PCREsearch.ini

Code: Select all

; for reference:
; \r   :: \x0d     :: Mac
; \n   :: \x0a     :: Unix
; \r\n :: \x0d\x0a :: Windows

[PCREsearch]
regexcount=3
regex1=\x0d(?!\x0a)
regex2=(?<!\x0d)\x0a
regex3=\x0d\x0a
regex1name=Mac
regex2name=Unix
regex3name=Win
regex1type=4
regex2type=4
regex3type=4
regex1replace=Mac
regex2replace=Unix
regex3replace=Win
TC .ini custom columns

Code: Select all

[CustomFields]
Titles=test line breaks
Headers1=Line break style
Contents1=[=pcresearch.Mac][=pcresearch.Unix][=pcresearch.Win]
Visualization:
Image: https://i.imgur.com/bwilrK9.png

Edit: regex*flags strings were removed from the example.
Last edited by beb on 2023-11-01, 12:01 UTC, edited 1 time in total.
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10
User avatar
white
Power Member
Power Member
Posts: 4622
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

Re: Content Plugin that shows line break style/type?

Post by *white »

beb wrote: 2023-11-01, 07:03 UTC

Code: Select all

regex1flags=0
regex2flags=0
regex3flags=0
Perhaps useful to use:
It's the sum of the following options:

8 : use the encoding check buffer (AnalyzeBuffer) for reading only
16 : disable text filter
User avatar
beb
Senior Member
Senior Member
Posts: 435
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

Re: Content Plugin that shows line break style/type?

Post by *beb »

2white
Maybe. It's also configurable by a plugin GUI config tool (PCREsearchConfig[64].exe).
Actually, it wasn't intended to be a part of my original message, so I better remove regex*flags strings from there.
Thank you.
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10
User avatar
Usher
Power Member
Power Member
Posts: 1675
Joined: 2011-03-11, 10:11 UTC

Re: Content Plugin that shows line break style/type?

Post by *Usher »

2beb
What about mixed case:
- Files with Unix style EOLs edited in Windows (some CRLF are present)
- Files with Windows style EOLs edited in Linux (some LF are present)
Andrzej P. Wozniak
Polish subforum moderator
User avatar
beb
Senior Member
Senior Member
Posts: 435
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

Re: Content Plugin that shows line break style/type?

Post by *beb »

2Usher
Upon a coincidence, reading this board just a couple of days ago I came across a tool, that seemed interesting, though not yet displayed a practical application for my everyday use cases, but still was worth taking note of.
Then I saw this request here and suggested that the said tool could fit the OP's needs.
Then I tried a tool myself for the very first time in my life, and the results obtained proved I wasn't that wrong.
Then I just gave an example in here of what output the said tool can provide to a user respecting the OP's request.
In no way I'm an expert in the said tool.
Nevertheless, any user feels free to adjust the plugin and try advanced output options according to their specific needs.

Returning to your question, regarding a mixed case.
The direct answer is as follows:
Within the example that I gave here in the morning, in case of a mixed case (where a file contains mixed line break entries of different kinds, CR, LF, or both), the example configuration will provide a fully expected mixed output.
I've seen how it works in this case while testing different files (including my screenshot images here), just didn't mention it here since it went out of the scope of the OP's request specifics (to detect if there are files with the wrong line break style within their dedicated collection of scripts where this element expected to be consistent).
Here is how it looks visualized (again, within nothing else but my example test configuration):
Image: https://i.imgur.com/NBFc6NS.png
:)

Edit:
For those fellow Total Commander users who might become interested in what content my .txt test files have, here they are:
Image: https://i.imgur.com/hPWicJa.jpg
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10
User avatar
Usher
Power Member
Power Member
Posts: 1675
Joined: 2011-03-11, 10:11 UTC

Re: Content Plugin that shows line break style/type?

Post by *Usher »

2beb
Thanks for the info.
However, it's not exactly what I asked. For my examples the tool should display "UnixWin" for the first case and "WinUnix" for the second one.
Last edited by Usher on 2023-11-02, 22:27 UTC, edited 1 time in total.
Andrzej P. Wozniak
Polish subforum moderator
User avatar
beb
Senior Member
Senior Member
Posts: 435
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

Re: Content Plugin that shows line break style/type?

Post by *beb »

2Usher
You're welcome.
Usher wrote: 2023-11-02, 17:21 UTC ...For my examples the tool should display "UnixWin" for the first case and "WinUnix" for the second one.
In my example configuration, where there are three positionally fixed regex conditions, it rather won't: I guess it will show "UnixWin" in both your cases since the sequence is [=pcresearch.Mac][=pcresearch.Unix][=pcresearch.Win].
Maybe it should and could if properly configured for your task/wish, though.
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10
User avatar
Dalai
Power Member
Power Member
Posts: 9389
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Re: Content Plugin that shows line break style/type?

Post by *Dalai »

2beb
Though I really appreciate the work you did, I won't be using this solution for several reasons:
  • The plugin is too complex for me and I like things simple. I need to be able to configure it to use it properly.
    The plugin files are also quite large for such a small and simple task. It would be a different story if I had other use cases for this plugin, but currently I don't.
  • The plugin is not able to provide fields of type ft_multiplechoice. There's no difference when showing a field in custom columns (both are strings), but it's not good for TC's Find Files; one needs to manually enter a string to search for a specific type which is both inconvenient and potentially error-prone.
  • I'm currently working on a (simple) content plugin that is able to do what I want and how I want. The basic framework is already done. Pretty sure I'm going to publish it once it's ready and has been tested extensively.
Nonetheless, thank you for your efforts! Perhaps other people can use a solution like this for their use case(s).

Regards
Dalai
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
User avatar
beb
Senior Member
Senior Member
Posts: 435
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

Re: Content Plugin that shows line break style/type?

Post by *beb »

2Dalai
Don't mention it. It's been my pleasure trying to chip in.
Surely, nothing wrong if you aren't fully satisfied with the available solutions.
And it's great if you can find your own way. That is how we are progressing.
I wish you all the best in your efforts.
Thank you for such a detailed message that (along with that discussion as a whole, I hope) could be pretty useful for other users who may meet similar challenges.
Cheers.
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10
Post Reply