WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

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

Offline jazzbiker

  • Sr. Member
  • ****
  • Posts: 263
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: 12060

Offline jazzbiker

  • Sr. Member
  • ****
  • Posts: 263
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: 846
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

  • Sr. Member
  • ****
  • Posts: 263
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: 846
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: 10217
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

  • Sr. Member
  • ****
  • Posts: 263
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!