NetAdminTools.com
 
SignalQ Sites:
NetAdminTools - Coprolite - NoNIC - SpotBridge - NAW
RoboCoop - AreWeDown - SolarPower - SysAdminTools
Xfig - Gold Loaf - GeekPapa - FixGMC - MCJ - FixRambler
Categories:
GNU/Linux | Homebrew designs | Perl | Administration | Backup/Recovery | Bugs/Fixes | Certification | Database | Email | File/Print | Hardware | Information Grab Bag | Interoperability | GNU/Linux ABCs | Monitoring | Name Resolution | Network Services | Networking | Remote Control | Security | Desktop | Web | BSD | Solaris | GIAGD | REALbasic

Last 30 Days | Last 60 Days | Last 90 Days | All Articles | RSS | Hail Support


Categories:
·GNU/Linux
·Homebrew designs
·Perl
·Administration
·Backup/Recovery
·Bugs/Fixes
·Certification
·Database
·Email
·File/Print
·Hardware
·Information Grab Bag
·Interoperability
·GNU/Linux ABCs
·Monitoring
·Name Resolution
·Network Services
·Networking
·Remote Control
·Security
·Desktop
·Web
·BSD
·Solaris
·GIAGD
·REALbasic
·All Categories


Using Tab2space to Convert Tabs to Spaces in Source Code
Topic: Web   Posted:2003-12-31
Printer Friendly: Print

spacerspacer
We often need to convert source code into html format. We use the pre tag; however, the default tab values are to wide. For instance:
this is one tab
this is another
If we were to put some of our funner source code up, it would push the right margin over too far. Well, we wrote about tidy in this article. It turns out that along with tidy there is a nice utility called tab2space that is just what we need. Say we have a script called source1.pl:

u-1@srv-1 t2s $ cat source1.pl
while (<>){
if (/ruk/) {
print;
}
else {
print "no go\n";
}
}
u-1@srv-1 t2s $
u-1@srv-1 t2s $ cat fl
ruk here
ruk there
ruk everywhere
not here
not there
but ruk here
u-1@srv-1 t2s $ perl source1.pl < fl
ruk here
ruk there
ruk everywhere
no go
no go
but ruk here
u-1@srv-1 t2s $

We can make the source easier to read with tab2space:

u-1@srv-1 t2s $ tab2space -h
tab2space: [options] [infile [outfile]] ...
Utility to expand tabs and ensure consistent line endings
options for tab2space vers: 6th February 2003
-help or -h     display this help message
-dos  or -crlf  set line ends to CRLF (PC-DOS/Windows - default)
-mac  or -cr    set line ends to CR (classic Mac OS)
-unix or -lf    set line ends to LF (Unix)
-tabs           preserve tabs, e.g. for Makefile
-t           set tabs to  (default is 4) spaces
Note this utility doesn't map spaces to tabs!
u-1@srv-1 t2s $ tab2space -t2 source1.pl             
while (<>){
if (/ruk/) {
print;
}
else {
print "no go\n";
}
}
u-1@srv-1 t2s $





Please read our Terms of Use
Microsoft, Windows, Windows XP, Windows 2003, Windows 2000, and NT are either trademarks or registered trademarks of Microsoft Corporation. NetAdminTools.com is not affiliated with Microsoft Corporation. Linux is a registered trademark of Linus Torvalds, and refers to the Linux kernel. The operating system of most distributions that contain the Linux kernel is GNU/Linux. All logos and trademarks in this site are property of their respective owner. Copyright 1997-2008 NetAdminTools.com

Created by:
MCJ
MCJ CMS