Carl Witthoft
Carl Witthoft

Reputation: 21532

Need DXL code to arrange attribute lines into table (converting DOORS data to LaTeX source)

I have a DXL script which parses all data in DOORS columns into a LaTeX -compatible text source file. What I can't figure out is how to re-order some data into a tabular - compatible format. The attributes in question are DXL links to a reference DOORS module, so there is one line (separated by a line-feed) per link in each cell. Currently I loop thru all columns for each object (row), with the code snippet (part of the full script)

   for col in doorsModule do {      
      var_name = title( col )    
      if( ! main( col ) && search( regexp "Absolute Number", var_name, 0 ) == false )
      { 
//  oss is my output stream variable 
        if ( length(text(col, obj) ) > 0 )
        {
             oss << "\\textbf{";
             oss << var_name;  // still the column title here    
                oss <<  "}\t"    
             var_name = text( col, obj );
             oss << var_name; 
             oss << "\n\n"; 
             c++;
        }
      }               
   }

Examples of the contents of a cell, where I have separately parsed the Column Name to bold and collected it prior to collecting the cell contents. All four lines are the contents of a single cell.

\textbf{LinkedItemName}
DISTANCE
MinSpeed
MaxSpeed
Time

\textbf{Unit}
m
km/h
km/h
minutes

\textbf{Driver1}
100
30
80
20

\textbf{Driver2}
50
20
60
10

\textbf{Driver3}
60
30
60
30

What I want to do is re-arrange the data so that I can write the source code for a table, to wit:

\textbf{LinkedItemName} & \textbf{Unit} & \textbf{Driver1} & \textbf{Driver2} & \textbf{Driver3} \\
DISTANCE & m & 100 & 50 & 60 \\
MinSpeed & km/h & 30 & 20 & 30 \\
MaxSpeed & km/h & 80 & 60 & 60 \\
Time & minutes & 20 & 10 & 30 \\

I know in advance the exact Attribute names I'm "collecting." I can't figure out how to manipulate the data returned from each cell (regex or otherwise) to create my desired final output. I'm guessing some regex code (in DXL) might be able to assign the contents of each line within a cell to a series of variables, but don't quite see how.

Upvotes: 0

Views: 562

Answers (1)

Carl Witthoft
Carl Witthoft

Reputation: 21532

Combination of regex and string assembly seems to work. Here's a sample bit of code (some of which is straight from the DOORS DXL Reference Manual)

int idx = 0
Array thewords = create(1,1)
Array  thelen = create(1,1)
Regexp getaline = regexp2 ".*"
// matches any character except newline
string txt1 = "line 1\nline two\nline three\n"
// 3 line string
while (!null txt1 && getaline txt1) {
    int ilen = length(txt1[match 0])
    print "ilen is " ilen "\n"
    put(thelen, ilen, idx, 0)
    putString(thewords,txt1[match 0],0,idx)
    idx ++ 
    // match 0 is whole of match
    txt1 = txt1[end 0 + 2:] // move past newline
}
int jj
// initialize to simplify adding the "&"
int lenone = (int get(thelen,0,0) )
string foo = (string get(thewords, 0, 0,lenone ) )
int lenout
for (jj = 1; jj < idx; jj++) {
    lenout = (int get(thelen,jj,0) )
    foo = foo "&" (string get(thewords, 0, jj,lenout ) )
}
foo = foo "\\\\" 

// foo is now  "line 1&line two&line three\\ " (without quotes) as LaTeX wants 

Upvotes: 0

Related Questions