NAME

aligneq - align = (or other strings) in text

SYNOPSIS

aligneq [-in] [-s string]... [-S string]... [file...]

DESCRIPTION

aligneq aligns the specified character sequences (default "=") in text. For example, given something like:

    a = 1 ;
    xyz = 3 ;
    aVeryLongSymbolName = 100 ;
  
it will output:
    a                   = 1 ;
    xyz                 = 3 ;
    aVeryLongSymbolName = 100 ;
  
By default, leading white space is not considered, so that:
    a = b ;
    xyz = c ;
    if ( i == j ) {
        x = y ;
    }
  
will result in:
    a   = b ;
    xyz = c ;
    if ( i == j ) {
        x   = y ;
    }
  
This behavior can be suppressed by means of the -i option, see below.

Note that the "==" is not aligned. By default, matching sequences are only aligned if they are set off by spaces. This behavior can be suppressed by means of the -n option.

The default matching string is designed to align = characters in all C/C++ assignment operators, including compound assignments, e.g.:

    a = b ;
    c += d ;
    x <<= 3 ;
  
results in:
    a   = b ;
    c  += d ;
    x <<= 3 ;
  

OPTIONS

The following options are supported:

-i
Ignore indentation, in other words, treat leading white space as if it were part of the left-hand text (see explination below).
-n
Do not implicitly surround match strings with spaces (see explication below).
-t  n
Expand tab characters as if tab-stops were every n columns (defaults to 8).
-s  string
Add the literal string to the list of separators to be recognized.
-S  string
Add the regular expression specified by the string to the list of separators to be recognized.

OPERANDS

The following operands are supported:

file
A pathname of an input file. If no file operands are specified, the standard input shall be used.

DETAILED DESCRIPTION

Before starting, all options are evaluated. The -s and -S are collected in a list; if this list is empty, then the list { "=", "+=", "-=", "*=", "/=", "%=", "&=", "|=", "^=", "<<=", ">>=" } is used, as if each string had been entered using the -s option. Strings given with the -s option are then "sanitized", i.e. any regular expression meta-characters they might contain are escaped. Each string is put into parentheses, and if the -n option is not present, a single blank is placed before and after the string. Finally, a regular expression is build from the or of all of the strings.

Processing takes place in two phases. First, the input is read one line at a time. Tabs are expanded, and each line is divided up into four parts: leading whitespace (aways empty if the -i option was given); the left hand side, up til the beginning of a match with the regular expression; the separator text, which is what matches the regular expression; and the right hand side, which is everything else. If no text matches the regular expression, the separator string and the right hand side are empty.

The alignment position is calculated by adding the maximum size of the left hand side to the maximum size of the separator string; only lines with a recognized separator are taken into account.

Finally, the lines are output. During output, if the line has a separator string, the left hand part is padded (on the right) to the alignment position minus the length of the separator string. (This effectively aligns the right most character of the separator string. Which turns out to be what is wanted in the case of C/C++ assignment operators like +=.)

EXAMPLES

In addition to the simple examples given above, given:

    int a ;
    double xyz ;
    MyClass c;
  
the command aligneq -n -S ' [[:alpha:]_]' outputs:
    int     a;
    double  xyz ;
    MyClass c;
  
followed with aligneq -n -s ';' gives:
    int     a  ;
    double  xyz;
    MyClass c  ;
  

In the initialization of a struct:

    { "name", value },
    { "longer name", x },
    { "n", someValue },
  
a pipe of aligneq -n -s ', ' | aligneq -n -s ' }' gives:
    { "name"       , value     },
    { "longer name", x         },
    { "n"          , someValue },
  
All that's left to do manually is to insert the column headers as comments.

EXIT STATUS

0 no error.
2 One of the input files could not be opened.
3 Hardware error on standard out.

BUGS

The entire program is far to oriented to C/C++/Java source code. There should be an option to align the left-most column of the separator strings, for example.

There's no support for multibyte characters, like UTF-8. Each byte is counted as a character.