Goutetsu Posted May 8, 2004 Share Posted May 8, 2004 I started using AutoIt a few days ago. Well, I was using Exe2Aut to look at other people's scripts, and I came across a few who removed the tabs to make their files smaller. Obviously, this made the scripts hard to read and I didn't want to go through and tab them all so I wrote this perl script to do it for me, as it is oh so good at handling text. I don't know if anyone else will have any use for this, but you never know. I have only tested this in Linux, but it should work fine in windows and other OSes. At the moment it works like this: perl autoittab.pl <autoitscript> The tabbed code is printed to the screen so I suggest you redirect to another file: perl autoittab.pl <untabbed script> > <new tabbed script> Note: These commands assume you are using some sort of perl for windows from the command line. Though the commands will also work in *nix type OSes. expandcollapse popup#!/usr/bin/perl # Make sure we use somewhat proper code. use strict; #$numtabs holds our current "tab level" my $numtabs = 0; #Read all files listed on the command line #line by line. while(<>) { #Remove all tabs at the beginning of the line s/^\t*//; #If the line begins with if, elseif, else, or endif (case insensitive) if(/^(?i:if|elseif|else|endif)\b/) { #handle the if structure handle_ifs($_); }elsif(/^(?i:do|until)\b/) #same as above but with do/until loops { handle_dos($_); }elsif(/^(?i:for|next)\b/) { handle_fors($_); }elsif(/^(?i:while|wend)\b/) { handle_whiles($_); }elsif(/^(?i:func|endfunc)\b/) { handle_funcs($_); }elsif(/^(?i:select|case|endselect)\b/) { handle_selects($_); }else { #Otherwise, we just have a line of code print(("\t" x $numtabs) . $_); } } #"\t" x $numtabs prints $numbtabs tabs sub handle_selects { if(/^select\b/i) { print(("\t" x $numtabs) . $_); $numtabs += 2; } if(/^case\b/i) { $numtabs--; print(("\t" x $numtabs) . $_); $numtabs++; } if(/^endselect\b/i) { $numtabs -= 2; print(("\t" x $numtabs) . $_); } } sub handle_ifs { if(/^if\b/i) { print(("\t" x $numtabs) . $_); unless(/^If\s+(.*?)\s+Then\s+([\$\w]+.*)/i) { $numtabs++; } } if(/^elseif\b/i) { $numtabs--; print(("\t" x $numtabs) . $_); $numtabs++; } if(/^else\b/i) { $numtabs--; print(("\t" x $numtabs) . $_); $numtabs++; } if(/^endif\b/i) { $numtabs--; print(("\t" x $numtabs) . $_); } } sub handle_dos { print(("\t" x $numtabs++) . $_) if(/^do\b/i); print(("\t" x --$numtabs) . $_) if(/^until\b/i); } sub handle_fors { print(("\t" x $numtabs++) . $_) if(/^for\b/i); print(("\t" x --$numtabs) . $_) if(/^next\b/i); } sub handle_whiles { print(("\t" x $numtabs++) . $_) if(/^while\b/i); print(("\t" x --$numtabs) . $_) if(/^wend\b/i); } sub handle_funcs { print(("\t" x $numtabs++) . $_) if(/^func\b/i); print(("\t" x --$numtabs) . $_) if(/^endfunc\b/i); } Link to comment Share on other sites More sharing options...
Developers Jos Posted May 8, 2004 Developers Share Posted May 8, 2004 (edited) Have a look at Tidy before you put alot of time in it Autoit3 Tidy: http://www.hiddensoft.com/forum/index.php?...indpost&p=12782-or- Scite Editor + Tidy Single setup: http://www.hiddensoft.com/fileman/users/jdeb/setupscite.exe Edited May 8, 2004 by JdeB SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Goutetsu Posted May 8, 2004 Author Share Posted May 8, 2004 (edited) Tidy looks nice. I usually code stuff myself if I can, so I didn't search for anything to format scripts for me. Oh well, maybe somewill make use of the code elsewhere. Edited May 8, 2004 by Goutetsu Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now