[Coco] cprep 1.9 multi-line concatenation

William Carlin whcarlinjr at gmail.com
Thu Oct 8 22:56:43 EDT 2020

I am trying to clean up some source code I'm working on and saw in the
cprep 1.9 documentation that cprep will concatenate lines that end with a
backslash '\' and newline character (ENTER I am assuming) into a single
line.  Here it a snippet from the documentation:

This version also has the following ANSI compatible features:

  * Optional trigraph expansion (engaged with -t switch)
  * Concatenation of any line ending with a \ and newline character

However, it does not seem to be doing as I am expecting.  Here is my line
of code:

strncat(line, \
" [                                                                    ", \
78 - strlen(package));

Which should concatenate to:

strncat(line, " [
         ", 78 - strlen(package));

So you don't have to count, there are 67 spaces between the left
bracket and the ending double quote.

When I run my program through the cprep I get this as the output:

strncat ( line , " [

        " , \
78 - strlen ( package ) ) ;

It looks like cprep will only concatenate the line at the first backslash
but is not doing it for the second backslash.  Is this a bug or expected

I also t the -c command line option for cprep:

Usage:   c_prep [-opt] <source file>

Options: -t Turn on trigraph expansion
         -d<name>[=<token-sequence>] defines name
         -c Switch to full ANSI mode
         -h Prints this help message
         -e[=<decimal>] edition #
         -l Copies source lines for ASM output

c_prep operates in Microware compatible mode unless the -c switch is

If I use the -c switch I get this:

strncat ( line , " [

        " , \
#line 27
78 - strlen ( package ) ) ;

I have the source code for cprep 1.9 ; Here is the relevant portion of code
that concatenates the lines:

char eflag;
int lnflag[2];  /* #line flag [0]=print b4 line [1]=print after */
int _line_; /* source file line number counter */

xtndln(a)   /* concatenate lines ending in \ */
register int a;
    if (line[a-1]=='\\')
        if (eflag)  /* if EOF */
            line[--a]=0;    /* Drop \ */
            a=getln(--a);     /* Drop \ and append next line */
            lnflag[1]=_line_;   /* set to print #line after line */
    return a;

eflag lets cprep know that EOF has been detected and that the file
currently being processed can be closed and to either begin processing the
next file or exit the program.

It seems to me that this code should be able to concatenate multiple lines
of code into a single line of code if each line ends with a backslash and a
line feed.


William Carlin

More information about the Coco mailing list