WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: busybox vi ":s" command  (Read 2969 times)

Offline jazzbiker

  • Hero Member
  • *****
  • Posts: 628
busybox vi ":s" command
« on: July 01, 2020, 08:08:19 AM »
Hi, Core people!

If anybody is interested in the patch for :s command in busybox-1.29.3 vi, I can post it. Enables full power extended regexps with backreferences in the search pattern and subpatterns substitution in replace field.

Regards!

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 13794

Offline jazzbiker

  • Hero Member
  • *****
  • Posts: 628
Re: busybox vi ":s" command
« Reply #2 on: July 02, 2020, 04:50:15 AM »
Hi, Juanito!

No, the patch You mention is trivial workaround for colon commands ranges. But the :s command currently is almost unfunctional, even worse than if compiled without VI_REGEX_SEARCH_ENABLED, because the use "(){}[]|" symbols in the "find" pattern causes wrong string lengths and broken output. Probably, I'm alone on this planet, using busybox vi.

Offline andyj

  • Hero Member
  • *****
  • Posts: 969
Re: busybox vi ":s" command
« Reply #3 on: July 02, 2020, 05:32:13 AM »
No, you're not alone, and I've noticed that the 's' command on busybox has been broken for as long as I've ever tried to use it. ESXi also uses busybox and it's broken there too so it's busybox, not just TC. That's why I either use sed or vim (which I maintain the extensions for so that I can have a working vi editor). Is this patch from upstream busybox, or somewhere else?

Offline jazzbiker

  • Hero Member
  • *****
  • Posts: 628
Re: busybox vi ":s" command
« Reply #4 on: July 02, 2020, 07:02:25 AM »
Hi, andyj!

Ok, there are at least two of us ;-) No, i didn't sent it to busybox. Previous my fix for backward search was ignored by busybox team, and I made the conclusion, that they are satisfied with vi functionality and don't want to waste time on unimportant issues. Probably busybox is mainly compiled without those strange regular expressions and everybody is happy.
So the patch I've made is used by myself only, and not tested by anybody else. Substantially it isn't the patch, because there were nothing to be patched concerning regexps. Two simple functions added, a couple of local variables added in the colon() function, xmalloc() and free() calls used, so memory leaks are possible. Globals untouched. Want to participate in testing?

Offline andyj

  • Hero Member
  • *****
  • Posts: 969
Re: busybox vi ":s" command
« Reply #5 on: July 02, 2020, 07:52:18 AM »
I can give it a try. Do you have both 32 and 64 bit versions, or just one of them?

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 10658
Re: busybox vi ":s" command
« Reply #6 on: July 02, 2020, 10:03:58 AM »
Denys, the BB maintainer, is often busy, and you need to ping your patch a couple times.
The only barriers that can stop you are the ones you create yourself.

Offline jazzbiker

  • Hero Member
  • *****
  • Posts: 628
Re: busybox vi ":s" command
« Reply #7 on: July 04, 2020, 06:58:36 AM »
Hi, curaga!

Clear, let's test this patch and if TinyCore comunity members and maintainers will account it useful I will accomodate it for the BB-current.

Hi, andyj!

Sorry for delay, I took some attempts to lower the memory consumption, but without success. The problem is that when we are using regexp find/replace the output string may be quite big even for very short command. And current vi memory model is : whole text placed in the RAM as a single chunk. So inserting X byte-long string inside the text of Y bytes size may require for at least 3*X+Y bytes for realloc(), don't forget about undo buffer. So I've made the dummy limit of 1M (MAX_SUBSTITUTED_LEN in the source) for substituted string length. Of course the smarter approach is to try allocate 3*X+Y, if failed then stop the operation, and in the case of success free this buf immediately and allocate the X-size buffer. If You will test the patch and approve it is working, I can continue with it. Another thing TODO is storing the last :s command data for further use as default, but this will need touching globals. Not a difficult issue, but not ready yet.

If You will build busybox-1.29.3, don't apply the vi-aimed patch from the repo src directory, apply only this one attached, it includes all: ranges, backward search and regexps.

I will wait for the reply.

Regards!

Offline jazzbiker

  • Hero Member
  • *****
  • Posts: 628
Re: busybox vi ":s" command
« Reply #8 on: June 26, 2021, 02:42:40 AM »
Hi, Core people!

If You sometimes look into busybox git log, You can notice that Ron Yorston has made o lot of patches for vi. Now he is helping me to make my patch more submittable. He proposed a lot of improvements and among them he proposes to use basic REGEXes instead of extended ones both for ':s' and '/' commands. Such change is orthogonal to whether my patch will be committed or not or another changes. But it may be harmful for those, who uses REGEXes in busybox vi.
As it  appeared, the only distributions which have busybox vi built with VI_REGEX_SEARCH option enbled are TinyCore Linux and Fedora. But Fedora have nano in the minimal distribution.
I guess it will be correct before making such changes to poll TinyCore developers about their attitude.

So the question is:

Will the use of basic REGEXes for busybox vi ':s' and '/' commands harm You?

Of course I'm most interested in Curaga, Juanito, Jason W, bmarkus and Paul_123 opinions, but everybody please answer, what kind of REGEXes do You prefer.

Best regards!

Edit:
vi is the only editor described in POSIX, and POSIX proposes basic REGEXes for vi. As far as I can notice, Ron's patches aim making busybox vi as much POSIX-compatibe as possible.
« Last Edit: June 26, 2021, 03:01:52 AM by jazzbiker »

Offline n0m0n

  • Newbie
  • *
  • Posts: 4
Re: busybox vi ":s" command
« Reply #9 on: June 26, 2021, 09:13:28 AM »
Hi, just wanted to say that I'd love to see better :s support in busybox vi. vim is lovly but often a bit overkill to install for quick edits/fixes.

Offline jazzbiker

  • Hero Member
  • *****
  • Posts: 628
Re: busybox vi ":s" command
« Reply #10 on: June 26, 2021, 10:16:43 AM »
Hi, n0m0n!

I can absolutely agree with You about vim. And sometimes You load into the clean system and simply have no other choices but busybox vi.

Offline jazzbiker

  • Hero Member
  • *****
  • Posts: 628
Re: busybox vi ":s" command
« Reply #11 on: July 14, 2021, 03:20:47 PM »
At least regex ":s" patch committed along with another nice patches by Ron Yorston.
https://git.busybox.net/busybox/commit/?id=95ac4a48f17c2fdd2a10524c0b399e3be72d8f42

Have a nice vi!