#! /usr/bin/awk -f
BEGIN {
    RS = ORS = "\r"
    lc=0 # State variable for continuing a C++ style Line comment
    cc=0 # State variable for continuing a C style comment
    qt=0 # quote-count
}

NR == 1 { print ""; next }

/^C/ { # Begin C-Style Comment
    if (qt % 2)
        next
    if (lc) {
        if ($0 ~ /\n/) {
            lc = 0
            sub(/\n.*/, "\n")
        }
    } else {
        cc = 1
    }
    print
    next
}
/^E/ { # End C-Style Comment
    if (qt % 2)
        next
    if (lc) {
        if ($0 ~ /\n/) {
            lc = 0
            sub(/\n.*/, "\n")
        }
        print 
    } else if (cc) {
        cc = 0
        if ($0 ~ /\n/)
            print "\n"
        else
            print "E"
    }
    next    
}
/^L/ { # Begin C++ Style Line Comment
    if (qt % 2)
        next
    if (!cc) {
        lc = 0
        if ($0 ~ /\n/)
            sub(/\n.*/, "\n")
        else
            lc = 1
    }
    print
    next
}
/^Q/ { # Quote
    if (lc || cc)
        print
    else
        qt++
    next
}
