@@ -41,8 +41,7 @@ internal static ReturnCode runOnce(TypeCobolConfiguration config)
4141                debugLine  +=  Path . GetFileName ( config . InputFiles [ 0 ] ) ; 
4242            } 
4343            debugLine  +=  "\n " ; 
44-             //Use user-defined log path if -log option used, otherwise use default location for log file 
45-             File . AppendAllText ( config . LogFile  ??  TypeCobolConfiguration . DefaultLogFileName ,  debugLine ) ; 
44+             Logger ( config ,  debugLine ) ; 
4645            Console . WriteLine ( debugLine ) ; 
4746            TextWriter  textWriter  =  config . ErrorFile  ==  null  ?   Console . Error  :  File . CreateText ( config . ErrorFile ) ; 
4847            AbstractErrorWriter  errorWriter ; 
@@ -84,8 +83,7 @@ internal static ReturnCode runOnce(TypeCobolConfiguration config)
8483
8584            stopWatch . Stop ( ) ; 
8685            debugLine  =  "                         parsed in "  +  stopWatch . Elapsed  +  " ms\n " ; 
87-             //Use user-defined log path if -log option used, otherwise use default location for log file 
88-             File . AppendAllText ( config . LogFile  ??  TypeCobolConfiguration . DefaultLogFileName ,  debugLine ) ; 
86+             Logger ( config ,  debugLine ) ; 
8987            Console . WriteLine ( debugLine ) ; 
9088
9189            AnalyticsWrapper . Telemetry . TrackMetricsEvent ( EventType . Duration ,  LogType . Genration ,  "ExecutionTime" ,  stopWatch . Elapsed . Milliseconds ) ; 
@@ -122,11 +120,11 @@ private ReturnCode Compile()
122120            var  rootSymbolTable  =  LoadIntrinsicsAndDependencies ( ) ; 
123121
124122            //Add analyzers 
125-             var  analyzerProvider  =  new  CompositeAnalyzerProvider ( ) ; 
123+             var  analyzerProvider  =  new  AnalyzerProviderWrapper ( str  =>   Logger ( _configuration ,   str ) ) ; 
126124            var  reports  =  RegisterAnalyzers ( analyzerProvider ) ; 
127125
128126            //Add external analyzers 
129-             analyzerProvider . AddCustomProviders ( _configuration . CustomAnalyzerFiles ) ; 
127+             analyzerProvider . AddCustomProviders ( _configuration . CustomAnalyzerFiles ,  str  =>   Logger ( _configuration ,   str ) ) ; 
130128
131129            //Normalize TypeCobolOptions, the parser does not need to go beyond SemanticCheck for the first phase 
132130            var  typeCobolOptions  =  new  TypeCobolOptions ( _configuration ) ; 
@@ -199,10 +197,24 @@ private ReturnCode Compile()
199197            //Write used and missing copies files 
200198            WriteCopiesFile ( _configuration . ExtractedCopiesFilePath ,  _usedCopies ) ; 
201199            WriteCopiesFile ( _configuration . HaltOnMissingCopyFilePath ,  _missingCopies ) ; 
200+ #if EUROINFO_RULES 
201+             WriteUsedCopiesFile ( ) ; 
202+ #endif
202203
203204            return  AddErrorsAndComputeReturnCode ( ) ; 
204205        } 
205206
207+         /// <summary> 
208+         /// Log a string in the LogFile provided by the configuration. 
209+         /// </summary> 
210+         /// <param name="config">Configuration containing the log file.</param> 
211+         /// <param name="message">String to log.</param> 
212+         private  static void  Logger ( TypeCobolConfiguration  config ,  string  message ) 
213+         { 
214+             //Use user-defined log path if -log option used, otherwise use default location for log file 
215+             File . AppendAllText ( config . LogFile  ??  TypeCobolConfiguration . DefaultLogFileName ,  message ) ; 
216+         } 
217+ 
206218        private  SymbolTable  LoadIntrinsicsAndDependencies ( ) 
207219        { 
208220            var  intrinsicsAndDependenciesParser  =  new  Parser ( ) ; 
@@ -251,21 +263,21 @@ private void CollectMissingCopies(IEnumerable<string> missingCopies)
251263            } 
252264        } 
253265
254-         private  Dictionary < string ,  IReport >  RegisterAnalyzers ( AnalyzerProvider   analyzerProvider ) 
266+         private  Dictionary < string ,  IReport >  RegisterAnalyzers ( AnalyzerProviderWrapper   analyzerProviderWrapper ) 
255267        { 
256268            var  reports  =  new  Dictionary < string ,  IReport > ( ) ; 
257269            if  ( _configuration . ExecToStep  >=  ExecutionStep . CrossCheck ) 
258270            { 
259271                //All purpose CFG/DFA 
260-                 analyzerProvider . AddActivator ( ( o ,  t )  =>  CfgDfaAnalyzerFactory . CreateCfgAnalyzer ( _configuration . CfgBuildingMode ) ) ; 
272+                 analyzerProviderWrapper . AddActivator ( ( o ,  t )  =>  CfgDfaAnalyzerFactory . CreateCfgAnalyzer ( _configuration . CfgBuildingMode ,   o ) ) ; 
261273
262274                //CFG/DFA for ZCALL report 
263275                if  ( ! string . IsNullOrEmpty ( _configuration . ReportZCallFilePath ) ) 
264276                { 
265277                    if  ( _configuration . CfgBuildingMode  !=  CfgBuildingMode . WithDfa ) 
266278                    { 
267279                        //Need to create a dedicated CFG builder with DFA activated 
268-                         analyzerProvider . AddActivator ( ( o ,  t )  =>  CfgDfaAnalyzerFactory . CreateCfgAnalyzer ( CfgBuildingMode . WithDfa ) ) ; 
280+                         analyzerProviderWrapper . AddActivator ( ( o ,  t )  =>  CfgDfaAnalyzerFactory . CreateCfgAnalyzer ( CfgBuildingMode . WithDfa ,   o ) ) ; 
269281                    } 
270282
271283                    string  zCallCfgDfaId  =  CfgDfaAnalyzerFactory . GetIdForMode ( CfgBuildingMode . WithDfa ) ; 
@@ -276,7 +288,7 @@ private Dictionary<string, IReport> RegisterAnalyzers(AnalyzerProvider analyzerP
276288                //CopyMoveInitializeReport 
277289                if  ( ! string . IsNullOrEmpty ( _configuration . ReportCopyMoveInitializeFilePath ) ) 
278290                { 
279-                     analyzerProvider . AddActivator ( 
291+                     analyzerProviderWrapper . AddActivator ( 
280292                        ( o ,  t )  => 
281293                        { 
282294                            var  report  =  new  CopyMoveInitializeReport ( ) ; 
@@ -461,6 +473,42 @@ private void WriteCopiesFile(string copiesFilePath, IEnumerable<string> copies)
461473            } 
462474        } 
463475
476+ #if EUROINFO_RULES 
477+         private  void  WriteUsedCopiesFile ( ) 
478+         { 
479+             if  ( _configuration . ReportUsedCopyNamesPath  !=  null ) 
480+             { 
481+                 using  ( var  output  =  File . CreateText ( _configuration . ReportUsedCopyNamesPath ) ) 
482+                 { 
483+                     foreach  ( var  parserResult  in  _parserResults ) 
484+                     { 
485+                         string  fileName  =  Path . GetFileNameWithoutExtension ( parserResult . Key ) ; 
486+                         var  usedCopies  =  parserResult . Value . CollectedCopyNames ; 
487+ 
488+                         if  ( usedCopies  ==  null ) 
489+                         { 
490+                             output . WriteLine ( fileName ) ; 
491+                             continue ; 
492+                         } 
493+ 
494+                         foreach  ( var  usedCopy  in  usedCopies ) 
495+                         { 
496+                             output . Write ( fileName ) ; 
497+                             output . Write ( ';' ) ; 
498+                             output . Write ( usedCopy . Key ) ; 
499+                             foreach  ( var  suffixedName  in  usedCopy . Value ) 
500+                             { 
501+                                 output . Write ( ';' ) ; 
502+                                 output . Write ( suffixedName ) ; 
503+                             } 
504+                             output . WriteLine ( ) ; 
505+                         } 
506+                     } 
507+                 } 
508+             } 
509+         } 
510+ #endif
511+ 
464512        private  ReturnCode  AddErrorsAndComputeReturnCode ( ) 
465513        { 
466514            /* 
@@ -513,7 +561,7 @@ private ReturnCode AddErrorsAndComputeReturnCode()
513561                        if  ( generationException . Logged ) 
514562                        { 
515563                            string  message  =  generationException . Message  +  Environment . NewLine  +  generationException . StackTrace ; 
516-                             var  position  =  new  Diagnostic . Position ( generationException . LineNumber ,  generationException . ColumnStartIndex ,  generationException . ColumnEndIndex ,  null ) ; 
564+                             var  position  =  new  Diagnostic . Position ( generationException . LineNumber ,  generationException . ColumnStartIndex ,  generationException . LineNumber ,   generationException . ColumnEndIndex ,  null ) ; 
517565                            Server . AddError ( _errorWriter ,  generationException . Path ,  new  Diagnostic ( generationException . MessageCode ,  position ,  message ) ) ; 
518566                        } 
519567                    } 
@@ -524,7 +572,20 @@ private ReturnCode AddErrorsAndComputeReturnCode()
524572            CheckExternalDiagnostics ( _dependenciesDiagnostics ) ; 
525573            CheckExternalDiagnostics ( _intrinsicsDiagnostics ) ; 
526574
527-             //Always return MissingCopy when there is at least one missing copy because it could help the developer to correct several parsing errors at once 
575+             //Avoid returning MissingCopy for users who are only interested in copies extraction 
576+             if  ( _configuration . ExecToStep  <=  ExecutionStep . Preprocessor ) 
577+             { 
578+ 	            if  ( _configuration . ExtractedCopiesFilePath  !=  null 
579+ #if EUROINFO_RULES 
580+ 	                ||  _configuration . ReportUsedCopyNamesPath  !=  null 
581+ #endif
582+ 	               ) 
583+ 	            { 
584+ 		            return  returnCode ; 
585+ 	            } 
586+             } 
587+ 
588+             //Return MissingCopy when there is at least one missing copy because it could help the developer to correct several parsing errors at once 
528589            if  ( _missingCopies . Count  >  0 ) 
529590            { 
530591                returnCode  =  ReturnCode . MissingCopy ; 
0 commit comments