Article View: comp.std.c
Article #2166Re: Re: C-formattors (problems with very long lines)
From: Hermann Stamm
Date: Wed, 30 Sep 1992 09:29
Date: Wed, 30 Sep 1992 09:29
121 lines
3323 bytes
3323 bytes
tomc@siesoft.co.uk (Tom Crossland) writes:
>
> hermann@uran.informatik.uni-bonn.de (Hermann Stamm) writes:
> : - insert a '\n' after each ';' found
>
> What about things like for(a=1; a<MAX; a*=2)...
> would become
>
> for(a=1;
> a<MAX;
> a*=2)...
>
> It should still compile, but it's hardly "beautified"
>
Perhaps this is not beautified, but it
a) works even on C-Sources with very long lines
b) can be beautified by a standard beautifier in
a second step
and it is a great help in debugging of lines with length
greater than i.e. xterm can capture.
Is there any fixed upper limit for line-length in the
ANSI-C-standard ?
The more important question I think, is, what is the reason for
standard C-beautifiers to break -> in the middle for long lines
(resulting in a compiler-error).
Do they use a fixed length buffer for handling logical lines?
--------------------------------------------------------------
fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
> hermann@uran.informatik.uni-bonn.de (Hermann Stamm) writes:
>
> >I wrote my own simple "C-beautifier", which simply does the
> >following:
> >
> > - discard empty lines
> > - insert a '\n' after each ';' found
> >
> >This works fine, but now I have 2 questions:
> >
> > 1. Is this a correct transformation of any C-Source ?
>
> No. You need to make sure that you don't insert newlines into string
> or character literals that may contain semi-colons.
Sorry, you are right!
Below you can find the little prog I am using. It detects both,
if a ; is inside "..." and inside ' ' . If so, it doesn't insert
the '\n' after the ; otherwise it does.
The question now is, does the below program correctly transforms
any compilable C-source into also compilable C-source.
Bye,
Hermann.
---------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
int main(int argc,char *argv[])
{
FILE *source,*target;
char c;
long z1,z2,l;
if (argc!=3)
{
fprintf(stderr,"Formtat: cb infile outfile\n");
exit(1);
}
if (NULL == (source = fopen(argv[1],"r")))
{
fprintf(stderr,"file not found !\n");
exit(2);
}
if (NULL == (target = fopen(argv[2],"w")))
{
fprintf(stderr,"target cannot be created !\n");
exit(3);
}
z1=z2=l=0;
while ((c=getc(source))!=-1)
{
if (c==34) z1^=1;
if (c==39) z2^=1;
if (c=='\n')
{
if (l>0)
{
putc(c,target);
l=0;
}
}
else
{
putc(c,target);
l++;
if ((c==';') && (z1==0) && (z2==0))
{
putc('\n',target);
l=0;
}
}
}
fclose(target);
fclose(source);
return(0);
}
Technical Details
Message-ID:
<1992Sep30.092907.28988@olymp.informatik.uni-bonn.de>Path:
arc1-ca.pugleaf.net!sparky!uunet!mcsun!Germany.EU.net!olymp!uran!hermannShow Full Headers
Complete Article Headers
Newsgroups: comp.std.c Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!Germany.EU.net!olymp!uran!hermann From: hermann@uran.informatik.uni-bonn.de (Hermann Stamm) Subject: Re: Re: C-formattors (problems with very long lines) Message-ID: <1992Sep30.092907.28988@olymp.informatik.uni-bonn.de> Sender: usenet@olymp.informatik.uni-bonn.de Reply-To: hermann@uran.informatik.uni-bonn.de (Hermann Stamm) Organization: Praktische Informatik III Date: Wed, 30 Sep 1992 09:29:07 GMT Lines: 123