Cover V09, I04
Listing 1
Listing 2
Sidebar 1


Recovering Source From a Defunct RCS System

Mike Dunham and Ed Schaefer

UNIX-based source code control systems, commercial or free-ware (that aren't SCCS), are probably Revision Control System (RCS) based. Recently, we had to recover very old source code from a defunct RCS-based system. The RCS clone's raw data files were available, but the system that generated the files was not. This article presents a UNIX shell script,, which recovers the last revision of the code from the raw data file.

In an RCS database, each source module is actually an ASCII flat file with the last revision of the source intact and previous revisions or deltas logged as sed-like commands. Listing 1 is a “C” demo, func.c, with a final revision of 1.3. The number of the last revision, 1.3, is stored in the “head” section of the file. Upon finding the revision number, search the file until you find the revision number with the following:

The source code for version 1.3 starts at this point and continues until you see one terminating “@” sign. Any source containing an “@” sign is expanded to “@@” by RCS.

If only a few files need to be converted, a developer with the VI editor could easily do the function that performs. If a large number of files need to be retrieved, this script eliminates tedious editing.

Pseudo Code for

To avoid destroying the original RCS file, the converted output file is stored with a .src extension in directory tst, below the present working directory. The psuedo code is:

1. Create an AWK script using the “here file” facility of the shell to retrieve the header revision number. The revision number format at the beginning of a line is:

   ^head {Revision #};
For each RCS file to be converted:

2. Execute the script created in step 1.

3. Create another AWK script looking for the revision number found in step 2. The format at the beginning of each line is:

   ^{Revision #}
   ^@ { Log Description for this version } {optionally @ here if \
                                            only one line}
4. Execute the AWK script built in step 3, sending the original source to the output file.

5. Cycle through the output file replacing any “@@” signs with a single “@” sign.


Listing 2 is the source for This article is one method for retrieving the latest version from RCS source code files. The obvious enhancements are to support retrieving branches and retrieving revisions other than the last revision. To implement this functionality, it is necessary to create a script or program that reads the RCS delta commands. Essentially, this creates your own RCS system -- something beyond the scope of our original mission.

About the Author

Michael Dunham is currently a senior programmer/analyst for Intel's Factory Information and Control System (IFICS) Group in Hillsboro, Oregon. He has eight years of experience developing and implementing systems on UNIX-based platforms. His experience includes working for Hewlett Packard and Consolidated Freightways writing real-time systems, automation interfaces, and maintaining enterprise manufacturing systems. He can be reached at:

Ed Schaefer is a senior programmer/analyst for Intel's Factory Information and Control System (IFICS) Group. His viewpoints on source code control or any other subject in no way reflect Intel's position. He can be reached at: