The MASM Forum

General => The Workshop => Topic started by: Siekmanski on July 17, 2012, 04:49:15 AM

Title: Replace tabs with spaces
Post by: Siekmanski on July 17, 2012, 04:49:15 AM
Is there a tool that fills the tabs of a source file with spaces ?
So if I post a source it's better readable if someone uses another tab space ?
Title: Re: Replace tabs with spaces
Post by: Ryan on July 17, 2012, 05:08:34 AM
I just do a Find/Replace in Word.  ^t is the escape for a tab.
Title: Re: Replace tabs with spaces
Post by: jj2007 on July 17, 2012, 06:36:58 AM
Instead of launching MS Word, try this - I hope it's self-explanatory ;-)

include \masm32\MasmBasic\MasmBasic.inc   ; download (http://masm32.com/board/index.php?topic=94.0)
   Init
   Let esi=Clip$()
   SetClip$ Cat$(Replace$(esi, Tb$, "    "))
   Exit
end start
Title: Re: Replace tabs with spaces
Post by: Siekmanski on July 17, 2012, 08:21:38 AM
Thanks.
I never used MasmBasic.....
Don't know what to do with Tabs2Spaces.exe ?
When I execute the file nothing happens.
Title: Re: Replace tabs with spaces
Post by: qWord on July 17, 2012, 08:27:49 AM
Quote from: Siekmanski on July 17, 2012, 08:21:38 AM
When I execute the file nothing happens.
the current clipboard content is manipulated
Title: Re: Replace tabs with spaces
Post by: dedndave on July 17, 2012, 09:25:28 PM
Swiss File Knife is a command-line tool that does all kinds of stuff
http://sourceforge.net/projects/swissfileknife/ (http://sourceforge.net/projects/swissfileknife/)
it's easy to write batch files that use it

Title: Re: Replace tabs with spaces
Post by: Siekmanski on July 18, 2012, 04:39:19 AM
I'll have a look at Swiss File Knife.
Title: Re: Replace tabs with spaces
Post by: jj2007 on July 18, 2012, 05:05:03 AM
Quote from: qWord on July 17, 2012, 08:27:49 AM
the current clipboard content is manipulated

Which is usually an unfriendly act, but when posting code to the Forum, you need to use it anyway ;-)

Here is a special variant for the Masm32 Forum:

include \masm32\MasmBasic\MasmBasic.inc       ; download (http://masm32.com/board/index.php?topic=94.0)
   Init
   Let esi=Clip$()       ; get clipboard text
   SetClip$ Cat$(Replace$(esi, Tb$, "    "))       ; set modified text with 4 spaces per tab
   .if WinByTitle("Post reply -")       ; check if the reply window is already open
      invoke SetForegroundWindow, eax       ; if yes, go there
   .endif
   Exit
end start

Of course, you need to launch the proggie. For use with QEditor, menus.ini needs a line like
Quote[&Tools]
...
Tabs to Spaces,{e}\masm32\Tabs2Spaces.exe
Title: Re: Replace tabs with spaces
Post by: hutch-- on July 18, 2012, 08:35:08 AM
Just write the algo, its no big deal to do. You need to know what spacing matches your tab settings but its just arithmetic and spaces as padding. QE does it automatically as you type.
Title: Re: Replace tabs with spaces
Post by: Siekmanski on July 18, 2012, 11:41:19 AM
QuoteJust write the algo, its no big deal to do.

You are right hutch, I'll write it myself. ( I was just in a lazy mood )  :biggrin:
Title: Re: Replace tabs with spaces
Post by: clive on July 19, 2012, 02:43:59 AM
Quote from: hutch-- on July 18, 2012, 08:35:08 AM
Just write the algo, its no big deal to do. You need to know what spacing matches your tab settings but its just arithmetic and spaces as padding.

Thank you, it's not just a find-and-replace, as a TAB attempts to push the column to 8, 4, or 2 characters, or whatever the alignment preference is.

They are pretty much noddy programs, I scratched up some DETABx and RETABx applications in C (I know) to transition between soft and hard tabs.