Combine C, C++ & Perl Source Code Files into one Document without Tabs

(Version 2)

What is It?

It is a trivial program which will combine multiple C, C++ & Perl source code files into one text file simultaneously converting the tabs in those files to spaces.

I wrote it to so as to be able to put a load of source code in the appendix of a wordprocessor document. Even when I set the font to fixed spacing, it still messed up the tab alignments (which were specified in distances not characters) so I use this to convert the tabs to space. Not having an easy way to combine the files in a sorted order (it being a Microsoft Windows system so there was not much of a shell script) I put that in the Perl script as well.

A Better Alternative

This program is rather obsolete because, 2 years after first writing this page, I found that there was a GNU program called source-highlight (also known as 'src-highlite') that not only can replace the tabs with spaces but output in HTML with syntax colour coding. I recommend you use that instead. However my old program is still here lest someone only needs plain text output & does not want to spend time installing a program (this being just a single file Perl script).

System Requirements

A Perl interpreter.

How to Use It

Run it with the directory to process as its sole parameter. It will copy the contents of every *.c, *.cpp, *.h, *.pl & *.txt file in that directory and all subdirectories thereof recursively.

The result will be output into a file called 'Combined.txt'.

Some Simple Customisations

The file extension list should cover typical C, C++ & Perl file names (and some general purpose text ones which may contain documentation). If want any others collected, just add their file extensions to the "txt|c|h|cpp|pl" in the Perl script.

It assumes tab stops every 4 characters. If you use a different spacing then just edit number in the "$tabstop=4;" line of the Perl script to that.


Download (3 Kb).

Other Perl Scripts, Disclaimers Etc.

See my computer programs index page for more simple useful computer programs.