#!/usr/bin/perl -w
# Auther: Wallacexiang
# Descrioption: This perl fuction is used to remove "parameterOrder" of ecc
# protocol v1.0.4 wsdl files. It is just helpfuf
# Update: 2008/4/22
# Use strict module.
use strict;
# Define the usage message for help.
my $usage = "Usage: command -c SpecifyTheDestDir -i SpecifyImportDir
/-f [WSDLfiles] file1 file2...";
# Define the inport directory for soapcpp2 comamnd.
my $importDir;
# Define the object directory for output files.
my $destDir;
# Hard code
$destDir = "temp/";
# Define arrary of the input .wsdl file.
my @inputWSDL;
# Analyse the command line parameter.
my $count = 0;
my $npara = @ARGV;
for($count = 0; $count < $npara; $count++) {
if ($ARGV[$count] eq "-c") {
$destDir = $ARGV[$count + 1];
}
if ($ARGV[$count] eq "-i") {
$importDir = $ARGV[$count + 1];
}
if ($ARGV[$count] eq "-f") {
my $num = 0;
my $tempcount = $count;
while(!($ARGV[$tempcount+1] =~ m/^-/) && !(length($ARGV[$tempcount+1]) == 2)) {
$tempcount++;
if ($tempcount >= $npara) {
last;
}
$inputWSDL[$num] = $ARGV[$tempcount];
print "$num/n";
$num++;
} # End while
} # End if
} # End for
print @inputWSDL, "/n";
print $inputWSDL[0], $inputWSDL[1], "/n";
print $importDir, "/n";
print $destDir, "/n";
# Create the dest directory.
my $dest = $destDir;
if (!defined($importDir)) {
$importDir = "/opt/gsoap-2.7/soapcpp2/import/";
}
# if (!defined($destDir)) {
# print "Specify the dest dirctory, $usage/n";
# exit(1);
# }
if (!defined($inputWSDL[0])) {
print "Specify the .wsdl file(s), $usage/n";
exit(1);
}
# my @sour_file_names = qw (Profile.wsdl common.wsdl ProblemReport.wsdl InventoryReport.wsdl ServiceProvider.wsdl StatusReport.wsdl UpdateOrder.wsdl);
my @sour_file_names = @inputWSDL;
my $sour_names;
my $time;
# my @sour_file_names = @inputWSDL
foreach $sour_names(@sour_file_names){
print "## $sour_names ##/n";
my $time = &replaceInFile("$sour_names","AAA$sour_names"," +parameterOrder=/"//w+ +//w+ +//w+/">",">");
print "the time of replacing is $time. /n/n";
}
# some order in the linux
# Add profix AAA to input .WSDL file.
my $num = 0;
while ($num < @inputWSDL) {
$inputWSDL[$num] = "AAA" . $inputWSDL[$num];
$num++;
}
my $wsdlString = join(" ", @inputWSDL);
print "$wsdlString/n";
# $destDir = "-d" . $destDir;
$importDir = "-I" . $importDir;
print "Execute: wsdl2h -t typemap.dat -o ecc.h $wsdlString.../n";
sleep(3);
system("wsdl2h -t typemap.dat -o ecc.h $wsdlString");
print "Execute: wsdl2h -t typemap.dat -o ecc.h $wsdlString.../n";
sleep(3);
system("soapcpp2 -d$destDir -x -C -L ecc.h $importDir");
sleep(1);
#
# Change boolean type in soap message from True/False to 1/0
#
@sour_file_names = qw (soapC.cpp soapClient.cpp);
# Change the work directory.
chdir $destDir;
foreach $sour_names(@sour_file_names) {
my $time = &replaceInFile("$sour_names","$sour_names","/"true/"","/"1/"");
$time = &replaceInFile("$sour_names","$sour_names","/"false/"","/"0/"");
}
# Save the *.h file name to .tempfilename
system("ls *.h > .tempfilename");
sleep(1);
open(FH, "<.tempfilename");
# Change the all *.h files to *.hpp files.
my @dothfilename = <FH>;
print @dothfilename, "/n";
my $objectfile;
for($num = 0; $num < @dothfilename; $num++) {
chomp $dothfilename[$num];
$objectfile = $dothfilename[$num] . "pp";
`mv "$dothfilename[$num]" "$objectfile"`;
}
close(FH);
system("rm -f .tempfilename");
# Step1: Add the specific log file to soapStup.hpp file.
my $logfile = "/n/#if defined(_WIN32) || defined(_WIN64)
/#pragma warning(disable: 4251)
extern SOAP_CMAC char g_TraceLogFile[_MAX_PATH];
/#else
extern /"C/"
{
extern SOAP_CMAC char g_TraceLogFile[PATH_MAX];
}
/#endif/n";
# Define the filename which will add log file.
my $filebeadd = "soapStub.hpp";
my @grepresult = `cat "$filebeadd" | grep -n "#include"`;
$_ = $grepresult[@grepresult - 1];
s/:#.*//;
my $lastnum = $_;
chomp($lastnum);
system("head -n $lastnum $filebeadd > .tempfile");
sleep(1);
# Begin add logfile
open(FH, ">>.tempfile");
print FH $logfile;
close(FH);
$lastnum++;
system("tail +$lastnum $filebeadd >> .tempfile");
sleep(1);
system("rm -f $filebeadd");
sleep(1);
system("mv .tempfile $filebeadd");
sleep(1);
# Step2: Add DLL_PRO_API to "soap_ptotocol __ProtocolWsdlVersion2s" func.
$sour_names = "soapH.hpp";
print "$sour_names/n";
my $sourStr = 'SOAP_FMAC3S const char/* SOAP_FMAC4S soap_protocol__ProtocolWsdlVersion2s';
my $destStr = 'DLL_PRO_API const char* SOAP_FMAC4S soap_protocol__ProtocolWsdlVersion2s';
print $sourStr, "/n", "$destStr", "/n";
&replaceInFile($sour_names, $sour_names, $sourStr, $destStr);
# Step3: hpp to cpp
my @hppfile = qw (soapProfileSoapBindingProxy.hpp soapInventoryReportSoapBindingProxy.hpp soapProblemReportSoapBindingProxy.hpp soapServiceProviderSoapBindingProxy.hpp soapStatusReportSoapBindingProxy.hpp);
foreach my $file(@hppfile) {
print "Process $file.../n";
sleep(1);
&hpptocpp($file);
}
print "Completed!/n";
#
# This functinon is use to create cpp file form the .h file.
#
sub hpptocpp() {
my $hppfile = $_[0];
if (!open(FH, "<$hppfile")) {
die "Can not open the file: $hppfile, $!/n";
}
my $cppfile = $hppfile;
$cppfile =~ s//.hpp//.cpp/;
print "$cppfile", "/n";
if (!open(DEST, ">$cppfile")) {
die "Can not open the file: $cppfile, $!/n";
}
# Print include info to .cpp file.
print DEST "#include /"$hppfile/"/n";
# Define class name.
my $classname;
my @hppcontext = <FH>;
my $line;
my @beginnum;
my $count = 0;
for($line = 0; $line < @hppcontext; $line++) {
# find the class name.
if($hppcontext[$line] =~ m/^/s*class/s+/S+/) {
$classname = $hppcontext[$line];
$classname =~ s/^/s*class/s+//;
$classname =~ s// / *.*//;
chomp($classname);
}
# Search the each function begin position of class.
if($hppcontext[$line] =~ m/^(/s*|/s*virtual|/s*virtual/s+int)/s+/S+/(.*/)/) {
$beginnum[$count] = $line;
$count++;
}
} # End for
close(FH);
for (my $n = 0; $n < @beginnum - 1; $n++) {
my $str = $hppcontext[$beginnum[$n]];
if ($str =~ m/^(/s*)virtual(/s)+int(/s)+(/S+)/(/) {
my $funcname = $4;
$hppcontext[$beginnum[$n]] =~ s//).*//);/;
$str =~ s/virtual//;
$str =~ s/($funcname)/${classname}::${funcname}/;
# Write to .cpp file
print DEST $str;
} elsif ($str =~ m/^(/s*)int(/s)+(/S+)/(/) {
my $funcname = $3;
$hppcontext[$beginnum[$n]] =~ s//).*//);/;
$str =~ s/($funcname)/${classname}::${funcname}/;
print DEST $str;
} elsif ($str =~ m/^(/s*)virtual(/s)+(/S+)/(/) {
my $funcname = $3;
$hppcontext[$beginnum[$n]] =~ s//).*//);/;
$str =~ s/virtual//;
$str =~ s/$funcname/${classname}::${funcname}/;
print DEST $str;
} elsif ($str =~ m/^(/s)+(/S+)/(/) {
my $funcname = $2;
$hppcontext[$beginnum[$n]] =~ s//).*//);/;
$str =~ s/($funcname)/${classname}::${funcname}/;
print DEST $str;
} else {
# TODO
}
if ($beginnum[$n+1]-$beginnum[$n] > 1) {
for (my $i = $beginnum[$n] + 1; $i <= ($beginnum[$n+1] - 1); $i++) {
print DEST $hppcontext[$i];
$hppcontext[$i] =~ s/.*//;
} # End for
} # End if.
} # End for
close(DEST);
if (!open(FH, ">$hppfile")) {
die "Can not open the file: $hppfile, $!/n";
}
print FH @hppcontext;
close(FH);
}
#
# The func is use to replace the specify string.
#
sub replaceInFile {
#get the source filename path and the destinion filename path
if(@_!=4){
print "WARNING! &replaceInFile should get exactly four arguments!/n";
exit(1);
}
my($sour_filename,$dest_filename,$search_string,$replace_string);
($sour_filename,$dest_filename,$search_string,$replace_string) = @_;
local *SOUR;
local *DEST;
if (!open (SOUR, $sour_filename)) {
die "Can not open the file : /"$sour_filename/"/n";
exit(1);
}
my $source; #store the content read from source file
my $count; #replace count
while (<SOUR>) {
$count = $count+s/$search_string/$replace_string/gs;
$source ="$source$_";
}
#print $source;
close(SOUR);
# Save the result into the destionion file.
if (!open (DEST,">$dest_filename")) {
die "Can not open";
}
print DEST $source; #write
close(DEST);
$count;
}
对gsoap生成的文件进行后期处理
最新推荐文章于 2025-04-07 10:48:03 发布