Post-processing of files generated by gsoap

Source: Internet
Author: User

#! /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

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 +/">", "> ");
Print "the time of replacing is $ time./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 ");

# Step 1: 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 );

# Step 2: 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 );

# Step 3: HPP to CPP
My @ hppfile = QW (soapprofilesoapbindingproxy. HPP soapinventoryreportsoapbindingproxy. HPP restart. 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 + /){
$ 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 + INT)/S + /(.*/)/){
$ Beginnum [$ count] = $ line;
$ Count ++;
}
} # End
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
} # End if.
} # End
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 shocould 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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.