From 4915b284cc20eec5648b7f57d90ce31635fd8c5b Mon Sep 17 00:00:00 2001 From: inoussa Date: Mon, 9 Nov 2009 10:02:37 +0000 Subject: [PATCH] Unit renaming option in ws_helper. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1000 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- wst/trunk/ws_helper/command_line_parser.pas | 10 ++++- wst/trunk/ws_helper/ws_helper_prog.inc | 43 +++++++++++++++++++-- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/wst/trunk/ws_helper/command_line_parser.pas b/wst/trunk/ws_helper/command_line_parser.pas index cf9d7f19d..49049f0c4 100644 --- a/wst/trunk/ws_helper/command_line_parser.pas +++ b/wst/trunk/ws_helper/command_line_parser.pas @@ -29,7 +29,8 @@ Type TComandLineOption = ( cloInterface, cloProxy, cloImp, cloBinder, cloWsdl, cloXsd, cloOutPutDirRelative, cloOutPutDirAbsolute, cloHandleWrappedParameters, - cloGenerateDocAsComments, cloGenerateObjectCollection + cloGenerateDocAsComments, cloGenerateObjectCollection, + cloFileRenaming ); TComandLineOptions = set of TComandLineOption; @@ -54,7 +55,7 @@ begin AAppOptions := []; c := #0; repeat - c := GetOpt('u:pibo:a:wxydg:'); + c := GetOpt('u:pibo:a:wxydg:f:'); case c of 'u' : begin @@ -83,6 +84,11 @@ begin Include(AAppOptions,cloGenerateObjectCollection); OptionsArgsMAP[cloGenerateObjectCollection] := OptArg; end; + 'f' : + begin + Include(AAppOptions,cloFileRenaming); + OptionsArgsMAP[cloFileRenaming] := OptArg; + end; end; until ( c = EndOfOptions ); Result := OptInd; diff --git a/wst/trunk/ws_helper/ws_helper_prog.inc b/wst/trunk/ws_helper/ws_helper_prog.inc index ab1645cd9..a997a8b1f 100644 --- a/wst/trunk/ws_helper/ws_helper_prog.inc +++ b/wst/trunk/ws_helper/ws_helper_prog.inc @@ -1,6 +1,6 @@ resourcestring - sUSAGE = 'ws_helper [-uMODE] [-gOPTION] [-p] [-b] [-i] [-w] [-x] [-y] [-d] [-oPATH] [-aPATH] inputFilename' + sNEW_LINE + + sUSAGE = 'ws_helper [-uMODE] [-gOPTION] [-p] [-b] [-i] [-w] [-x] [-y] [-d] -[fSPECIFACTIONS] [-oPATH] [-aPATH] inputFilename' + sNEW_LINE + ' -u MODE Generate the pascal translation of the WSDL input file ' + sNEW_LINE + ' MODE value may be U for used types or A for all types' + sNEW_LINE + ' -g Code generation option, with the following options : ' + sNEW_LINE + @@ -14,7 +14,8 @@ resourcestring ' -w Generate WSDL file; Can be used to get wsdl from pascal' + sNEW_LINE + ' -x Generate XSD file; Can be used to get xsd from pascal' + sNEW_LINE + ' -y Generate easy access interface for wrapped parameters' + sNEW_LINE + - ' -d Generate documentation as comment in the interface file.'; + ' -d Generate documentation as comment in the interface file' + sNEW_LINE + + ' -f Specify unit(s) renaming option : oldName= NewName(;oldName= NewName)* '; sCOPYRIGHT = 'ws_helper, Web Service Toolkit 0.6 Copyright (c) 2006, 2007, 2008 by Inoussa OUEDRAOGO'; type @@ -167,6 +168,41 @@ var end; end; + procedure HandleUnitRenaming(); + var + namesSpecif, strBuffer, oldName, newName : string; + k : Integer; + mdlList : TList; + mdl : TPasModule; + found : Boolean; + begin + namesSpecif := Trim(GetOptionArg(cloFileRenaming)); + Write('Handling unit renaming ... '); + WriteLn(namesSpecif); + mdlList := symtable.Package.Modules; + strBuffer := namesSpecif; + while True do begin + oldName := GetToken(strBuffer,'='); + if IsStrEmpty(oldName) then + Break; + newName := GetToken(strBuffer,';'); + if IsStrEmpty(newName) then + raise Exception.CreateFmt('Invalid option unit renaming specification : "%s".',[namesSpecif]); + found := False; + for k := 0 to Pred(mdlList.Count) do begin + mdl := TPasModule(mdlList[k]); + if SameText(oldName,mdl.Name) then begin + mdl.Name := newName; + WriteLn(Format('Unit renamed, old name = "%s", new name = "%s".',[oldName,newName])); + found := True; + Break; + end; + end; + if not found then + WriteLn(Format('Unit not found : "%s".',[oldName])); + end; + end; + function ProcessFile():Boolean; Var mtdaFS: TMemoryStream; @@ -177,6 +213,7 @@ var wrappedParams : Boolean; begin Result := False; + HandleUnitRenaming(); wrappedParams := ( cloHandleWrappedParameters in AppOptions ); strStream := nil; rsrcStrm := nil; @@ -232,7 +269,7 @@ var rsrcStrm := TMemoryStream.Create(); mtdaFS.Position := 0; BinToWstRessource(UpperCase(symtable.CurrentModule.Name),mtdaFS,rsrcStrm); - rsrcStrm.SaveToFile(outPath + ChangeFileExt(ExtractFileName(inFileName),'.' + sWST_EXTENSION)); + rsrcStrm.SaveToFile(outPath + ChangeFileExt(ExtractFileName(symtable.CurrentModule.Name),'.' + sWST_EXTENSION)); end; if ( cloWsdl in AppOptions ) then begin