IBM Support

How to implement word wrap feature for Rational Rhapsody comments using C++ COM API

Technote (FAQ)


Question

How do you implement word wrap feature for IBM Rational Rhapsody comments using C++ COM API?

Cause

You would like to use a C++ script to modify the generated code as per your specific requirement, which is not possible using the GUI.

Answer

In order to implement word wrap feature for Rational Rhapsody comments using C++ COM API, you can use the below C++ post processing script:

Disclaimer

All source code and/or binaries attached to this document are referred to here as "the Program". IBM is not providing program services of any kind for the Program. IBM is providing the Program on an "AS IS" basis without warranty of any kind. IBM WILL NOT BE LIABLE FOR ANY ACTUAL, DIRECT, SPECIAL, INCIDENTAL, OR INDIRECT DAMAGES OR FOR ANY ECONOMIC CONSEQUENTIAL DAMAGES (INCLUDING LOST PROFITS OR SAVINGS), EVEN IF IBM, OR ITS RESELLER, HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.




#include "stdio.h"
#include <string>
#include <conio.h>
#include <iostream>
#include <fstream>

using namespace std;

string wordWrap( string str, size_t width ) {
    size_t curWidth = width;
    while( curWidth < str.length() ) {
        std::string::size_type spacePos = str.rfind( ' ', curWidth );
        if( spacePos == std::string::npos )
            spacePos = str.find( ' ', curWidth );
        if( spacePos != std::string::npos ) {
            str[ spacePos ] = '\n';
            curWidth = spacePos + width + 1;
        }
    }

    return str;
}

static void process( const char* filename ) {

string lineString, tempString, fileString;
int flag = 0, flag1 = 0;

fstream in( filename );

if ( !in ) {
cout << filename << " does not exist!" << endl;
} else {
while ( getline(in, lineString,'\n')) {

int found = lineString.find("/* ");
if(lineString.find(" */")>117 && string::npos != lineString.find(" */"))
if(found!=string::npos) {

if(string::npos == lineString.find("/* Constructors and destructors:*/"))
if(string::npos == lineString.find("/* Operations */")) {

tempString = lineString;
string splitString = "", blankString = "";

for(int i = 0; i<found; i++)
blankString += " ";

string wrapString = wordWrap(lineString.substr(found+3, lineString.length()),114);
wrapString = wrapString.substr(0, wrapString.length()-3);
int found2 = wrapString.find("\n");
splitString = lineString.substr(0,found) + "/* ";
while(found2>0) {
splitString += wrapString.substr(0,found2) + " */" + "\n" + blankString + "/* ";
wrapString = wrapString.substr(found2+1, wrapString.length());
found2 = wrapString.find("\n");
}
splitString += wrapString + " */";
lineString = splitString;
}
}

fileString += lineString + '\n';
}

in.close();
ofstream out(filename, ios::ate );
out.seekp(ios::beg);
out << fileString;
out.close();
}
}

int main(int argc, char* argv[]) {

char fileName[80];

if ( argc > 1 ) {
strcpy (fileName, argv[1] );
process(fileName);
} else {
printf ("Missing arguments\n");
}
return 0;
}


You will need to convert the above code to an executable using any C++ IDE [say Microsoft Visual Studio 6] and use the same in the property CG:: File::InvokePostProcessor

Document information

More support for: Rational Rhapsody
General Information

Software version: 7.5, 7.5.0.1, 7.5.1, 7.5.1.1, 7.5.2, 7.5.2.1, 7.5.3, 7.5.3.1, 7.5.3.2, 7.6, 7.6.0.1, 7.6.1

Operating system(s): Windows

Reference #: 1587341

Modified date: 30 March 2012