[Coco] cprep 1.9 multi-line concatenation

William Carlin whcarlinjr at gmail.com
Mon Oct 12 13:40:30 EDT 2020


Update.  Bug fixed in cprep 1.9

I did not clarify in my previous email that this is the cprep 1.8 by Jim
McDowell of JML SOFTWARE DESIGN with 1.9 updates by Gene Heskett from the
glory days of Color Computer 3 OS-9 C programming circa 1993.

My issue is that cprep did not concatenate more than one line when a
backslash was the last character of a line, immediately followed by a
carriage return ($0D).

I added a line to the xtndln() function to update the length of the line
post concatenation and then recursed the function until the last
concatenation completes.

[cp.c] (Just the relevant function)

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


Here is my test file and the results:

[testcat]
Line 1 \
Line 2 \
Line 3 \
Line 4
Line 5
Line 6 \
Line 7 \
Line 8
Line 9 \
Line 10 \
Line 11 \
Line 12 \
Line 13
Line 14
END

Results of the fixed cprep 1.9

{N2|03}/DD/USR/SRC/TEST:cprep testcat
#7
testcat
testcat
#P
testcat
0
#5
0
Line 1 Line 2 Line 3 Line 4
#5
4
Line 5
Line 6 Line 7 Line 8
#5
8
Line 9 Line 10 Line 11 Line 12 Line 13
#5
13
Line 14
END

It seems that when this line of code is processed:

              a=getln(--a);     /* Drop \ and append next line */

The 'a' variable was not being updated to the last character of the line to
indicate the length of the line after concatenation.  When I added my fix,
I updated the length of the line by passing strlen(line) instead of 'a'.  I
may go back and take a look at the getln() function to see why the 'a' is
not being returned with the updated count of characters in the line.


William Carlin


On Thu, Oct 8, 2020 at 10:56 PM William Carlin <whcarlinjr at gmail.com> wrote:

>
> 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 , " [
>
>         " , \
> #5
> 27
> 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
> behavior?
>
> 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
> invoked.
>
> 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:
>
> [cp.h]
> char eflag;
> int lnflag[2];  /* #line flag [0]=print b4 line [1]=print after */
> int _line_; /* source file line number counter */
>
> [cp.c]
> xtndln(a)   /* concatenate lines ending in \ */
> register int a;
> {
>     if (line[a-1]=='\\')
>     {
>         if (eflag)  /* if EOF */
>             line[--a]=0;    /* Drop \ */
>         else
>         {
>             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.
>
> Thanks,
>
>
> William Carlin
>
>


More information about the Coco mailing list