SourceMerge

 

[SourceMerge] SourceMerge is an utility that let you maintain different versions of the same source code. This is NOT a revision control system: it is especially useful for producing programs in different languages. Since it is very configurable, it can be adopted for many different programming languages: C, C++, Html, Assembly, Clipper. These pages are maintained with SourceMerge.

 

Type Version Description Requirements Features Download

 

Type

Utility for Dos/Windows; freeware/GNU General Public License 2.0.

 

Version

1.2 / english.

 

Description

This program can be used to maintain different versions of the same source code. It is especially useful for producing programs in different languages. Since it is very configurable, it can be adopted for many different languages: C, C++, Html, Assembly, Clipper.
SourceMerge can be used on text files for Dos/Windows, Macintosh and Unix, even mixed (i.e. library file in one format, source file in another). Text files created have always the same format as the corresponding source file.

 

Requirements
Features

As usual, an example is the easiest way to demonstrate SourceMerge's use.
The command line for it is as follow:

SRCMERGE spec /Llib /Vver [/Sxy] [/Ddest] [/Brem_begin] [/Erem_end] [/X]

"spec" is the pathname of the files to process, including wild cards.
SourceMerge supports long file names under Windows 9x/ME/2000/XP; it also supports multiple wild cards '*' and '?' both under real Ms-Dos and Windows. Use parameter /X to avoid long file name matching.

"lib" is the name of the library file to be used; it can have any extension, even though I use ".LIB" in these examples.
The library file is a text file formatted like an .INI file for Windows.
Each section starts with:

[id:ver]

and ends with the next section or the end of file.
The characters '[' and ']' enclosing id:ver can be changed by using parameter /Sxy - x stands for prefix and y for suffix (each one is 1 character long): this can be useful if the text to be replaced can contain a line similar to a section start.

For example, suppose that you have this C fragment that defines two strings into the file SAMPLE.C:

#define WELCOME "Benvenuto"
#define BYE "Arrivederci"

The strings are in Italian; if you want to produce two versions of the same program, one in Italian and the other in English, replace the text above with:

/* SRCM:welc_bye. */
/* /SRCM:welc_bye. */

and create the library file MYTEST.LIB with this text:

[welc_bye:italian]
#define WELCOME "Benvenuto"
#define BYE "Arrivederci"
[welc_bye:english]
#define WELCOME "Welcome"
#define BYE "Goodbye"

Now, to create a version in one language or the other use:

SRCMERGE sample.c /lmytest.lib /vitalian
SRCMERGE sample.c /lmytest.lib /venglish

Of course, in this case it would be easier to put all definitions into the source code and select one version or the other with #ifdef; but there are languages in which this is impossible to do, and cases more sophisticated in which the same thing is not so easy (e.g. when you actually must add code for specific versions). Moreover, the source code is cleaner and more comprehensible to read by using this method.

As you should have noticed, each section in the source code is a block of text starting with:

b SRCM:id. e

and ending with:

b /SRCM:id. e

Optional text can be inserted between the '.' and 'e'; it is simply ignored.

The characters 'b' and 'e' are remark strings which can be specified with parameters /B and /E; if not specified, they are guessed according to source file extension, as in this table:

Extension .C .H .CPP .HPP .HTM .PRG .CH .INI .SYS .BAT .MNU .ASM other
'b' string /* /* // // <!-- * * rem rem rem ; # #
'e' string */ */     -->                

As you can see, 'e' strings can be empty; in this case, the tag ends at the end of line:

printf("this is a test\n"); // SRCM:id. <-- tag ends at the end of line

There must be exactly one space between the remark string 'b' and "SRCM:".

The parameters /L and /V must always be specified: the first defines the library file to be used, the second the version with which update on source files will take place.
Remember that both version tags and section IDs are case sensitive: italian and Italian are two different version tags, just like welc_bye and Welc_Bye are two different section IDs.

On command line, strings for version/remarks and characters to be used for prefix/suffix of section (parameter /S) can include C-like constants; for example, if you have an HTML file with the extension ".DOS" (which is unknown to SourceMerge) and you want to use the string "<!--" for 'b' and "-->" for 'e', type:

SRCMERGE test.dos /Ltest.lib /Vtest /B\x3c!-- /E--\x3e

This is necessary since the characters "<" and ">" are preprocessed by Dos and are used to redirect standard input/output from/to a file; their corresponding C-like strings are:

Character Hexadecimal Octal Decimal Ascii
< \x3c \074 \d60 60
> \x3e \076 \d62 62

Likewise, if you want to use the characters '|' for section prefix and '^' for section suffix, on the command line you could use:

/S\x7c^ /S\d124^ /S\174^ (character '^' can safely appear as it is)

The following escape sequences are supported:

\a \b \f \n \r \t \v \\ \? \' \"

and octal, hexadecimal and decimal constants thus specified:

Characters ':' and '.' must be avoided in version strings, just like Ascii characters below ' ' (32) in both remark and version strings.

By default, SourceMerge modifies source files 'in place', i.e. the files are overwritten with the updated version. If you want to create the new version in a different directory, use the parameter /D to set destination; in this case, source files won't be touched.
Remember that all files existing in destination directory are overwritten without notice.

Error level is set on exit to:

0 no errors
1 missing/wrong command line parameters, empty library
2 read/write/open error
3 id not found/syntax error
4 string too long
5 insufficient memory

Source files (when parameter /D is not specified) are overwritten only if the update is succesfull; if /D is used and SourceMerge exits with error level 3 or above, the last file created in the destination directory will be truncated at the point in which the error happened.

If SourceMerge doesn't find any section to update in a certain file, it will:

  1. not overwrite the file (if /D is not specified);
  2. create a copy of the file with the same date/time as the original (if /D is specified).

Run SRCMERGE without parameters to have a short summary of its usage.

 

Download

Download SourceMerge (version 1.2 for Dos/Windows)

 

Top of page