Untabify source code?

cKGunslinger

Lifer
Nov 29, 1999
16,408
57
91
I'm looking for some tool (free, preferable OSS) that will take in a bunch of text files (source code), or an entire directory structure and recursively convert all tab to spaces.

I'm pretty sure this is a trivial script in perl, but that's not really an option for this environment. I could also manually convert them with Visual Studio's editor (or just about any other editor), but I haven't seen a way to automate or batch this process.

Since the code I'm working with is contributed by several people each using a different IDE, I can't really control whether they have their editors set up to do tabs instead of spaces, so I'd really like a quick and user-friendly tool that each person could run on their code before submitting it.

I'm looking at writing this myself (should be relatively simple, even in C/C++), but I thought I'd cast about and see if someone has already done this first.

Any ideas?
 

Drakkon

Diamond Member
Aug 14, 2001
8,401
1
0
you could use something like textpad and do a find a replace on all /t such that it replaces them with " " for all documents
 

cKGunslinger

Lifer
Nov 29, 1999
16,408
57
91
Originally posted by: Drakkon
you could use something like textpad and do a find a replace on all /t such that it replaces them with " " for all documents

Yeah, removing tabs on single files manually is no prob, and there are literally dozens of ways to accomplish that, but I guess I'm looking for more of an automated solution...
 

Drakkon

Diamond Member
Aug 14, 2001
8,401
1
0
textpad is automated...you can open up a ton of files at once and its replace has a checkbox that goes through all of them (under scope do "all document") I do it all the time to XML files to replace a tag or add an attribute...
 

cKGunslinger

Lifer
Nov 29, 1999
16,408
57
91
Originally posted by: Drakkon
textpad is automated...you can open up a ton of files at once and its replace has a checkbox that goes through all of them (under scope do "all document") I do it all the time to XML files to replace a tag or add an attribute...

*checks it out*

Thanks.
 

spacelord

Platinum Member
Oct 11, 2002
2,127
0
76
UltraEdit has a "Tabs to Spaces" option under "Format"
edit: oops, not open source or free...
 

Armitage

Banned
Feb 23, 2001
8,086
0
0
Here's a python script that should work.
Note that replacing all of the tabs is easy. Excuding tab characters that might be in string variables may be a bit harder!

 

cKGunslinger

Lifer
Nov 29, 1999
16,408
57
91
Originally posted by: Armitage
Here's a python script that should work.
Note that replacing all of the tabs is easy. Excuding tab characters that might be in string variables may be a bit harder!
LOL - yeah, I was playing around with a perl script in cygwin that looked remarkably like that one. :p While that would take care of my first prob (mass removing of tabs on the entire project,) I'm not sure installing a scripting environment on the user's machines is an viable option.

I'd really like to be able to to email a smallish windows app to each one and say "run this on your code before you submit it." It'd not be much more than a dialog box asking for a file or directory, then a "working" indicator, then a "completed" notification.

I think I may just play around with some MFC code and see what I can come up with..

Thanks.
 

Armitage

Banned
Feb 23, 2001
8,086
0
0
It sounds like you're working with a revision control system.
Why not have a script somewhere that checks out a working copy, runs the detabify script on it, and checks in anything that changes with a simple message: "Detabified"

You could run it nightly, weekly, whatever. And you don't have to put anything else on your user's machines, or depend on them remembering to run it.
 

randumb

Platinum Member
Mar 27, 2003
2,324
0
0
Originally posted by: cKGunslinger
Originally posted by: Armitage
Here's a python script that should work.
Note that replacing all of the tabs is easy. Excuding tab characters that might be in string variables may be a bit harder!
LOL - yeah, I was playing around with a perl script in cygwin that looked remarkably like that one. :p While that would take care of my first prob (mass removing of tabs on the entire project,) I'm not sure installing a scripting environment on the user's machines is an viable option.

I'd really like to be able to to email a smallish windows app to each one and say "run this on your code before you submit it." It'd not be much more than a dialog box asking for a file or directory, then a "working" indicator, then a "completed" notification.

I think I may just play around with some MFC code and see what I can come up with..

Thanks.

py2exe is your friend :)
 

lansalot

Senior member
Jan 25, 2005
298
0
0
for a in (*.src) do (
sed 's/\t/ /g' %a>%a.new
del %a
ren %a.new %a
)

Find 'sed' on the net, download and run. Subsitute two %'s for each one in the above if you put that in a batch file

eg, "del %%a"