682 {
683 options opts;
684
685 if (!parse_arguments(argc, argv, opts)) {
686 std::cout << R"(
687 ____ ____ __ __ ___ _ _ _____ ___
688 | _ \ / ___| \/ | |_ _| \ | | ___/ _ \
689 | | | | | | |\/| | | || \| | |_ | | | |
690 | |_| | |___| | | | | || |\ | _|| |_| |
691 |____/ \____|_| |_| |___|_| \_|_| \___/
692
693 DICOM File Summary Utility
694)" << "\n";
695 print_usage(argv[0]);
696 return 1;
697 }
698
699
700 std::vector<std::filesystem::path> all_files;
701 for (const auto& path : opts.paths) {
702 if (!std::filesystem::exists(path)) {
703 std::cerr << "Error: Path does not exist: " << path.string() << "\n";
704 return 2;
705 }
706
707 if (std::filesystem::is_directory(path)) {
708 auto dir_files = collect_files(path, opts.recursive);
709 all_files.insert(all_files.end(), dir_files.begin(), dir_files.end());
710 } else {
711 all_files.push_back(path);
712 }
713 }
714
715 if (all_files.empty()) {
716 std::cerr << "Error: No DICOM files found\n";
717 return 2;
718 }
719
720
721 if (opts.format == output_format::text && !opts.quiet) {
722 std::cout << R"(
723 ____ ____ __ __ ___ _ _ _____ ___
724 | _ \ / ___| \/ | |_ _| \ | | ___/ _ \
725 | | | | | | |\/| | | || \| | |_ | | | |
726 | |_| | |___| | | | | || |\ | _|| |_| |
727 |____/ \____|_| |_| |___|_| \_|_| \___/
728
729 DICOM File Summary Utility
730)" << "\n";
731
732 if (all_files.size() > 1) {
733 std::cout << "Processing " << all_files.size() << " files...\n\n";
734 }
735 }
736
737
738 if (opts.format == output_format::json && all_files.size() > 1) {
739 std::cout << "[\n";
740 }
741
742 int exit_code = 0;
743 for (size_t i = 0; i < all_files.size(); ++i) {
744 bool is_last = (i == all_files.size() - 1);
745 if (process_file(all_files[i], opts, is_last) != 0) {