mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 19:22:45 +00:00 
			
		
		
		
	grep: Properly update match state when handling files
This commit is contained in:
		
							parent
							
								
									c1004b095e
								
							
						
					
					
						commit
						21bbff0349
					
				
					 1 changed files with 6 additions and 3 deletions
				
			
		|  | @ -186,8 +186,10 @@ ErrorOr<int> serenity_main(Main::Arguments args) | |||
|             return false; | ||||
|         }; | ||||
| 
 | ||||
|         bool did_match_something = false; | ||||
| 
 | ||||
|         auto handle_file = [&matches, binary_mode, suppress_errors, count_lines, quiet_mode, | ||||
|                                user_specified_multiple_files, &matched_line_count](StringView filename, bool print_filename) -> bool { | ||||
|                                user_specified_multiple_files, &matched_line_count, &did_match_something](StringView filename, bool print_filename) -> bool { | ||||
|             auto file = Core::File::construct(filename); | ||||
|             if (!file->open(Core::OpenMode::ReadOnly)) { | ||||
|                 if (!suppress_errors) | ||||
|  | @ -208,7 +210,9 @@ ErrorOr<int> serenity_main(Main::Arguments args) | |||
|                 auto line = file->read_line(file_size); | ||||
|                 auto is_binary = memchr(line.characters(), 0, line.length()) != nullptr; | ||||
| 
 | ||||
|                 if (matches(line, filename, line_number, print_filename, is_binary) && is_binary && binary_mode == BinaryFileMode::Binary) | ||||
|                 auto matched = matches(line, filename, line_number, print_filename, is_binary); | ||||
|                 did_match_something = did_match_something || matched; | ||||
|                 if (matched && is_binary && binary_mode == BinaryFileMode::Binary) | ||||
|                     break; | ||||
|             } | ||||
| 
 | ||||
|  | @ -236,7 +240,6 @@ ErrorOr<int> serenity_main(Main::Arguments args) | |||
|             } | ||||
|         }; | ||||
| 
 | ||||
|         bool did_match_something = false; | ||||
|         if (!files.size() && !recursive) { | ||||
|             char* line = nullptr; | ||||
|             size_t line_len = 0; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Tim Schumacher
						Tim Schumacher