Hello Yvonne,

Wednesday, June 27, 2001, Yvonne Murphy <[EMAIL PROTECTED]> wrote:

YM> The following is the complete code segment. I didn't use strict in the
YM> first half of the script because the Text:Tabs module would not work
YM> when I used it, so please don't hassle me about this. The main aim was
YM> to use C::Scan module to pick out the function declarations from a C
YM> header file. These are dumped to the 'functions2.log' file and this
YM> output is shown below also.

ok, here is explanation:

YM> #! /usr/local/bin/perl -w

YM> require 'dumpvar.pl';
YM> use Text::Tabs;
YM> use C::Scan;


YM> $tabstop = 1;

YM> $infile = "foo2.h"; #original header file to be parsed
YM> open(FOO2, "$infile") or die $!;
YM> @lines_with_tabs = <FOO2>; #read header file into array
YM> close(FOO2);

open(FOO3, ">>foo3.h"); #open a new file to store the header file when
YM> tabs are removed
YM> select(FOO3);

YM> print expand(@lines_with_tabs,"\n"); #remove the tabs and print it to
YM> 'foo3.h' file

YM> $c = new C::Scan 'filename' => 'foo3.h'; #create a C::Scan pointing to
YM> the header file

YM> $decl_function = $c->get('fdecls'); #scan for function declarations

just a little surprise from C::Scan - after doing this call variable
$/=undef.

perdoc perlvar:
....
$INPUT_RECORD_SEPARATOR
$RS
$/
The input record separator, newline by default. 
....


YM>open(FILE, ">>functions2.log") or die $!; #file used to dump the
YM> functions declarations to later on.
YM> select(FILE);
YM>dumpValue({fdecls =>> $decl_function});#function decls dumped to file

YM> close (FILE);
YM> close (FOO3);

YM> print STDOUT "See functions2.log file for output....\n\n";



YM> use strict;

YM> #this part is to remove the functions from the qoutes that
YM> #were added when the C::Scan was done.
YM> open (FUNCFILE, "functions2.log") or die $!;
open (OUTFILE, ">>thosecoolfuncs.log");
YM> my($mymatch,$line,@arr,$arr,$i);
YM> while ($mymatch = <FUNCFILE>) {

as $/ is undef, $mymatch contains all "functions2.log" up to undef,
i.e. to end of file. no more string-by-string reading. you can check
this by printing $mymatch at this point. All your troubles
follows from C::Scan.
so, you can:
1. forget about C::Scan module
2. make copy of $/ variable ( $save=$/; at start, and $/=$save; after
   C::Scan call )


Suggestions:
1. you can avoid more troubles by using something like

for(my $i=0; $i <= $#$decl_function; $i++)
{
 print FILE $$decl_function[$i],"\n";
}
instead of
dumpValue({fdecls =>> $decl_function});#function decls dumped to file

2. your algorythm does not handle multistring function definition.
   
YM>   # () required in "my($match) =" for list context
YM>      my($match) = $mymatch =~  m/\'(.+?)\;/gis;
YM>      print OUTFILE $match,  "\n\n" if $match;
YM> # if ($mymatch =~  m/\'(.+)\;/gis) { #matches anything between the
YM> single qoute and semi-colon and places it in the '$1' variable


YM> #         print OUTFILE $1,  "\n\n";
YM>  # print OUTFILE $1,"{"," \n","}",  "\n\n";
YM>  # }
YM>       }
YM> close (OUTFILE);
YM> close (FUNCFILE);

YM> #This part is for breaking up the lines into individual
YM> #words so that I'll be able to reference them with
YM> #such variable names as $ret_type, $function_name,$param etc.

YM> #$numlines = 0;
YM> open (INFILE, "thosecoolfuncs.log") or die $!;


YM>  while ($line = <INFILE>){
YM>   #chomp;
YM>   @arr = split(/[ (,)]+/, $line); #splits $line into words
YM>                                  #and stored in @arr.Words
YM>                                  #are separated by spaces,
YM>                                  #braces or commas.

YM>   for ($i=0; $i<=10; $i++) {

YM>     print STDOUT $arr[$i],"\n";
YM>     print STDOUT  "\n";
YM>    }
YM>   }
YM> close INFILE
[...]

Best wishes,
 Maxim                            mailto:[EMAIL PROTECTED]


Reply via email to