PROGRAM Win2Unix; {-- *************************************************************************** -- ** Descr. : Changes file references to all lowercase/uppercase so that there -- ** are no problems moving forms application from windows to the -- ** file upper/lowercase sensitive unix enviroment -- ** -- ** MINVERS: requires FormsAPI Master 1.0 Build 222 and up -- *************************************************************************** -- ** 05/12/01 1.001.00 Initial Creation, muellers@orcl-toolbox.com -- ** 17/04/02 1.002.00 fix usage of wrong property D2FP_LIB_SRC to -- ** D2FP_LIB_LOC, muellers@orcl-toolbox.com -- ** 17/12/05 1.003.00 ignore calls to OPEN_FORM/etc in comments, muellers@orcl-toolbox.com -- ** 23/02/06 1.004.00 change case of filename on save, muellers@orcl-toolbox.com -- ***************************************************************************} {*Global Variable Declaration*} VAR v_filename : varchar2; i,j : number; frm : number; files : TStringList; objlist : TStringList; tmplist : TStringList; v_oldfile : varchar2; v_newfile : varchar2; isChange : boolean; ps : TParamScreen; pb : TParamBoard; v_upper : boolean; v_save : boolean; FUNCTION ChangeCase (s : varchar2) : varchar2; BEGIN if v_upper then result := upper(s) else result := lower(s); END; PROCEDURE ReportAdd(i_obj : number; i_oldfile : varchar2; i_newfile : varchar2); BEGIN LogAdd(' => '+api_getobjectpath(i_obj)+' '+i_oldfile+'=>'+i_newfile); END; FUNCTION CheckPLSQL(s : varchar2; i_proc : varchar2; i_param : varchar2; i_parampos : number; i_obj : number) : varchar2; var x : number; oname,fname, s2: varchar2; apo : number; i : number; BEGIN s2 := BlendOut_PLSQL_Comments(s); x := 1; while x>0 do begin x := Find_PLSQL_Word(s2,i_proc,x); if x>0 then begin oname := ltrim(get_plsql_param (s,x, i_parampos, i_param)); if ctrim(oname)<>'' then begin fname := oname; isChange := false; //count apostrophes to check if the filename is a simple textstring! apo := 0; for i:=1 to length(oname) do if oname[i]='''' then inc(apo); if (upper(substr(fname,1,5))='LOWER') and (v_upper=false) then begin {ignore!} end else if (upper(substr(fname,1,5))='UPPER') and (v_upper=true) then begin {ignore!} end else if (apo=2) and (substr(fname,1,1)='''') then begin //is simple text! isChange := fname <> ChangeCase(fname); fname := ChangeCase(fname); end else begin //must then be function call or concatenated strings ?! if v_upper then fname := 'upper('+fname+')' else fname := 'lower('+fname+')'; isChange := true; end; if isChange then begin s := set_plsql_param(s,x, i_parampos, i_param,fname); s2 := set_plsql_param(s2,x, i_parampos, i_param,fname); ReportAdd(i_obj,'call to ['+i_proc+'] changed from ['+oname+'] to ['+fname+'] at line '+inttostr(Get_LineNumberAtPos(s,x)),''); end; end; x := x+1; end; end; result := s; END; {*Main Program Block*} BEGIN //build together a nice parameter screen ... ps := TParamScreen.create; ps.caption := 'Windows 2 Unix ...'; pb := ps.AddBoard('Modules',picModules); pb.addparam(parLabel,'MYLABEL','This script will change all referenced file names to uppper/lowercase. '+ 'Please make sure all referenced objects are in the same source path or the forms will fail to load - this is a limitation '+ 'of Oracles FormsAPI !','',''); pb.addparam(parPathname,'SRCPATH','Source Path','',''); pb.addparam(parPathname,'TRGPATH','Target Path','',''); pb.addparam(parRadioGroup,'OPERATION','Operation','Just Report','Just Report'+c_cr+'Change'); ps.parambyname('OPERATION').isNewGroup := true; pb.addparam(parComboListbox,'UPLOW','Filecase','Lower','Lower'+c_cr+'Upper'); pb.addparam(parDatabaseLogon,'MYDATABASE','Connect(opt)','scott/tiger',''); //show the parameter screen and wait for inputs if ps.ShowParamScreen then begin //because it is nice in the log to see what parameters we have specified //we just write them out logadd('Parameters:'); for j := 0 to ps.paramcount-1 do logadd(rpad(ps.param[j].name,20)+ps.param[j].value); // basic parametercheck ... if ps.ParamByName('SRCPATH').value ='' then raiseException('Missing Source Path!'); if (ps.ParamByName('TRGPATH').value ='') and (ps.ParamByName('OPERATION').value ='Change') then raiseException('Missing Target Path!'); try api_Connect(ps.ParamByName('MYDATABASE').value); except end; v_upper := ps.ParamByName('UPLOW').value ='Upper'; v_save := ps.ParamByName('OPERATION').value ='Change'; //get the list of fmb-modules to process (with all subdirectories) files := GetFileList(ps.ParamByName('SRCPATH').value,'*.fmb;*.mmb;*.olb;*.pll', true); for j := 0 to files.count-1 do begin v_filename := files.strings[j]; logadd('Checking ('+to_char(j+1)+'/'+to_char(files.count)+') '+v_filename); try SetCurrentPath(ExtractFilePath(v_filename)); frm := API_LoadModule(v_filename); objlist := API_GetAllObjects(frm); for i := 0 to objlist.count-1 do begin //check subclassed elements if Generic_HasProp(objlist.objects[i],D2FP_PAR_FLNAM) then begin if Generic_GetTextProp(objlist.objects[i],D2FP_PAR_FLPATH) ='' then v_oldfile := Generic_GetTextProp(objlist.objects[i],D2FP_PAR_FLNAM) else v_oldfile := Generic_GetTextProp(objlist.objects[i],D2FP_PAR_FLPATH)+'\'+ Generic_GetTextProp(objlist.objects[i],D2FP_PAR_FLNAM); v_newfile := ChangeCase(ExtractFileName(v_oldfile)); if v_newfile<>v_oldfile then begin Generic_SetTextProp(objlist.objects[i],D2FP_PAR_FLNAM,v_newfile); Generic_SetTextProp(objlist.objects[i],D2FP_PAR_FLPATH,''); ReportAdd(objlist.objects[i],v_oldfile,v_newfile); end; end; //check icon filenames if Generic_HasProp(objlist.objects[i],D2FP_ICON_FLNAM)then begin v_oldfile := Generic_GetTextProp(objlist.objects[i],D2FP_ICON_FLNAM); v_newfile := ExtractFileName(v_oldfile); if upper(ExtractFileExt(v_newfile)) = '.ICO' then v_newfile := ChangeFileExt(v_newfile,''); if upper(ExtractFileExt(v_newfile)) = '.GIF' then v_newfile := ChangeFileExt(v_newfile,''); v_newfile := ChangeCase(v_newfile); if v_newfile<>v_oldfile then begin Generic_SetTextProp(objlist.objects[i],D2FP_ICON_FLNAM,v_newfile); ReportAdd(objlist.objects[i],v_oldfile,v_newfile); end; end; //check library attachments, remove path and extension also if Generic_QueryType(objlist.objects[i])=D2FFO_ATT_LIB then begin v_oldfile := Generic_GetTextProp(objlist.objects[i],D2FP_LIB_LOC); v_newfile := ExtractFileName(v_oldfile); if upper(ExtractFileExt(v_newfile)) = '.PLL' then v_newfile := ChangeFileExt(v_newfile,''); if upper(ExtractFileExt(v_newfile)) = '.PLX' then v_newfile := ChangeFileExt(v_newfile,''); v_newfile := ChangeCase(v_newfile); if v_newfile<>v_oldfile then begin Generic_SetTextProp(objlist.objects[i],D2FP_LIB_LOC,v_newfile); ReportAdd(objlist.objects[i],v_oldfile,v_newfile); end; end; //check report objects if Generic_QueryType(objlist.objects[i])=D2FFO_REPORT then begin v_oldfile := Generic_GetTextProp(objlist.objects[i],D2FP_FLNAM); v_newfile := ChangeCase(ExtractFileName(v_oldfile)); if v_newfile<>v_oldfile then begin Generic_SetTextProp(objlist.objects[i],D2FP_FLNAM,v_newfile); ReportAdd(objlist.objects[i],v_oldfile,v_newfile); end; end; //check program units for calls to run_product/call_form/open_form if Generic_hasProp(objlist.objects[i],D2FP_PGU_TXT) then begin v_oldfile := Generic_GetTextProp(objlist.objects[i],D2FP_PGU_TXT); v_newfile := CheckPLSQL(v_oldfile,'CALL_FORM','formmodule_name',0,objlist.objects[i]); v_newfile := CheckPLSQL(v_newfile,'NEW_FORM','formmodule_name',0,objlist.objects[i]); v_newfile := CheckPLSQL(v_newfile,'OPEN_FORM','form_name',0,objlist.objects[i]); v_newfile := CheckPLSQL(v_newfile,'RUN_PRODUCT','module',1,objlist.objects[i]); if v_newfile<>v_oldfile then begin Generic_SetTextProp(objlist.objects[i],D2FP_PGU_TXT,v_newfile); end; end; //check triggers for calls to run_product/call_form/open_form if Generic_hasProp(objlist.objects[i],D2FP_TRG_TXT) then begin v_oldfile := Generic_GetTextProp(objlist.objects[i],D2FP_TRG_TXT); v_newfile := CheckPLSQL(v_oldfile,'CALL_FORM','formmodule_name',0,objlist.objects[i]); v_newfile := CheckPLSQL(v_newfile,'NEW_FORM','formmodule_name',0,objlist.objects[i]); v_newfile := CheckPLSQL(v_newfile,'OPEN_FORM','form_name',0,objlist.objects[i]); v_newfile := CheckPLSQL(v_newfile,'RUN_PRODUCT','module',1,objlist.objects[i]); if v_newfile<>v_oldfile then begin Generic_SetTextProp(objlist.objects[i],D2FP_TRG_TXT,v_newfile); end; end; end; logadd('Finished checking '+v_filename+' - '+to_char(objlist.count) +' objects scanned'); objlist.free; if v_save then begin //now modify the filename to point to the new location v_filename := substr(v_filename,length(ps.ParamByName('SRCPATH').value)+1); v_filename := ps.ParamByName('TRGPATH').value + v_filename; CreateDirectory(ExtractFilePath(v_filename)); //save it to the new location try API_SaveModule(frm,ChangeCase(v_filename)); except logadd('error saving file! - '+GetError,logerror); end; end; //... and finally release the module from memory API_DestroyModule(frm); except // ups! an error happened, so just log it and proceed to the next module logadd(' =>'+GetError,LogError); end; end; end else begin //user must have pressed cancel on parameterscreen logadd('Canceled on parameterscreen!'); end; // free the parameter screen ps.free; END.