develooper Front page | perl.perl5.porters | Postings from February 2008

[patch] Porting/expand-macros.pl gets 'indent'ing

Thread Next
From:
Jim Cromie
Date:
February 7, 2008 16:03
Subject:
[patch] Porting/expand-macros.pl gets 'indent'ing
Message ID:
47AB9C4A.3080107@gmail.com

this trivial patch gives new pretty-print output by using /usr/bin/indent,
when -f (for formatted) is given on cmdline.

For example:

$ perl ../expmac/Porting/expand-macro.pl -f CopFILE

`sh cflags "optimize='-g3 -ggdb -O2'" try.c` -E try.c > try.i
CCCMD = cc -DPERL_CORE -c -DPERL_PATCHNUM=33245 -DDEBUGGING 
-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include 
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm -std=c89 
-g3 -ggdb -O2 -Wall -ansi -W -Wextra -Wdeclaration-after-statement 
-Wendif-labels -Wc++-compat
# 3 "CopFILE expands to"
(((A0)->cop_filegv) && ((*(
{
GV * const shplep = (GV *) (((A0)->cop_filegv));
((((svtype) ((shplep)->sv_flags & 0xff)) ==
SVt_PVGV
|| ((svtype) ((shplep)->sv_flags & 0xff)) ==
SVt_PVLV) ? (void) (0) :
__assert_fail
("((svtype)((shplep)->sv_flags & 0xff)) == SVt_PVGV || 
((svtype)((shplep)->sv_flags & 0xff)) == SVt_PVLV",
"CopFILE expands to", 3, __PRETTY_FUNCTION__));
((((((shplep)->
sv_flags & (0x00004000 | 0x00008000)) ==
0x00008000)
&& (((svtype) ((shplep)->sv_flags & 0xff)) ==
SVt_PVGV
|| ((svtype) ((shplep)->sv_flags & 0xff))
==
SVt_PVLV))) ? (void) (0) :
__assert_fail
("((((shplep)->sv_flags & (0x00004000|0x00008000)) == 0x00008000) && 
(((svtype)((shplep)->sv_flags & 0xff)) == SVt_PVGV || 
((svtype)((shplep)->sv_flags & 0xff)) == SVt_PVLV))",
"CopFILE expands to", 3, __PRETTY_FUNCTION__));
&((shplep)->sv_u.svu_gp);
}))->gp_sv) ? (*(

{
SV * const _svi = (SV *) (((*(
{
GV
*
const
shplep
=
(GV
*)
(((A0)->cop_filegv));
((((svtype) ((shplep)->sv_flags & 0xff)) == SVt_PVGV || ((svtype) 
((shplep)->sv_flags & 0xff)) == SVt_PVLV) ? (void) (0) : __assert_fail 
("((svtype)((shplep)->sv_flags & 0xff)) == SVt_PVGV || 
((svtype)((shplep)->sv_flags & 0xff)) == SVt_PVLV", "CopFILE expands 
to", 3, __PRETTY_FUNCTION__));
((((((shplep)->sv_flags & (0x00004000 | 0x00008000)) == 0x00008000) && 
(((svtype) ((shplep)->sv_flags & 0xff)) == SVt_PVGV || ((svtype) 
((shplep)->sv_flags & 0xff)) == SVt_PVLV))) ? (void) (0) : __assert_fail 
("((((shplep)->sv_flags & (0x00004000|0x00008000)) == 0x00008000) && 
(((svtype)((shplep)->sv_flags & 0xff)) == SVt_PVGV || 
((svtype)((shplep)->sv_flags & 0xff)) == SVt_PVLV))", "CopFILE expands 
to", 3, __PRETTY_FUNCTION__));
&
((shplep)->sv_u.svu_gp);
}))->
gp_sv));
((((svtype)
((_svi)->sv_flags & 0xff)) >=
SVt_PV) ? (void) (0) :

....

THe example goes on for a while further, which is quite scary ;-)


Ive used Getopt::Std, this seems warranted in a useful tool, no user 
wont have it.


$ perl -w Porting/expand-macro.pl -ekvf -I -gnu
missing <macro-name>;
usage: ../expmac/Porting/expand-macro.pl [options] <macro-name> [headers]
options:
-f use 'indent' to format output
-F <tool> use <tool> to format output (instead of -f)
-e erase try.[ic] instead of failing when theyre present (errdetect)
-k keep them after generating (for handy inspection)
-v verbose
-I <indent-opts> passed into indent

with -I-v, indent gives many warnings:

indent: try.i:29541: Warning:Line broken 2
indent: try.i:29541: Warning:Line broken 2
indent: try.i:29541: Warning:Line broken 2
indent: try.i:29541: Warning:Line broken 2
indent: try.i:29541: Warning:Line broken 2

FWIW, I tried compiling try.c after running with -k, I get a compile err
that might be related to the above. I dont really know whether this
is meaningful.

$ make try
cc -fstack-protector -L/usr/local/lib try.c -o try
CopFILE expands to:3: error: expected ‘)’ before ‘->’ token
CopFILE expands to:3: error: expected ‘)’ before ‘&&’ token
make: *** [try] Error 1


with -f, indent works a large file, but it seems more than fast enough.


have fun with it
jimc

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About