Skip to content

Commit 5587213

Browse files
authored
style: Turn on clang-format for ivmain.cpp (#4382)
It was disabled to make prettier formatting for getargs, but neglected to turn it back on for the rest of the file. I also changed a few old `<<` stream output to `print()`. Signed-off-by: Larry Gritz <lg@larrygritz.com>
1 parent ef5dd61 commit 5587213

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

src/iv/ivmain.cpp

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ getargs(int argc, char* argv[])
7676

7777
ap.parse(argc, (const char**)argv);
7878
return ap;
79+
// clang-format on
7980
}
8081

8182

@@ -107,12 +108,12 @@ main(int argc, char* argv[])
107108
// LG
108109
// Q_INIT_RESOURCE(iv);
109110
QApplication app(argc, argv);
110-
111+
111112
std::string color_space = ap["image-color-space"].as_string("");
112113
std::string display = ap["display"].as_string("");
113114
std::string view = ap["view"].as_string("");
114115
// std::string look = ap["look"].as_string("");
115-
116+
116117
bool use_ocio = color_space != "" && display != "" && view != "";
117118
std::string ocioenv = Sysutil::getenv("OCIO");
118119
if (ocioenv.empty() || !Filesystem::exists(ocioenv)) {
@@ -123,9 +124,9 @@ main(int argc, char* argv[])
123124
#endif
124125
}
125126

126-
ImageViewer* mainWin = new ImageViewer(use_ocio, color_space, display,
127+
ImageViewer* mainWin = new ImageViewer(use_ocio, color_space, display,
127128
view);
128-
129+
129130
mainWin->show();
130131

131132
// Set up the imagecache with parameters that make sense for iv
@@ -142,19 +143,20 @@ main(int argc, char* argv[])
142143
mainWin->activateWindow();
143144

144145
ustring uexists("exists");
145-
std::vector<std::string> extensionsVector; // Vector to hold all extensions
146+
std::vector<std::string> extensionsVector; // Vector to hold all extensions
146147
auto all_extensions = OIIO::get_string_attribute("extension_list");
147-
for (auto oneformat : OIIO::Strutil::splitsv(all_extensions, ";")) { // Split the extensions by semicolon
148+
for (auto oneformat : OIIO::Strutil::splitsv(all_extensions, ";")) {
149+
// Split the extensions by semicolon
148150
auto format_exts = OIIO::Strutil::splitsv(oneformat, ":", 2);
149151
for (auto ext : OIIO::Strutil::splitsv(format_exts[1], ","))
150-
extensionsVector.emplace_back(ext);
152+
extensionsVector.emplace_back(ext);
151153
}
152154

153155
// Add the images
154156
for (auto& f : ap["filename"].as_vec<std::string>()) {
155157
// Check if the file exists
156158
if (!Filesystem::exists(f)) {
157-
std::cerr << "Error: File or directory does not exist: " << f << "\n";
159+
print(stderr, "Error: File or directory does not exist: {}\n", f);
158160
continue;
159161
}
160162

@@ -165,26 +167,33 @@ main(int argc, char* argv[])
165167

166168
std::vector<std::string> validImages; // Vector to hold valid images
167169
for (auto& file : files) {
168-
std::string extension = Filesystem::extension(file).substr(1); // Remove the leading dot
169-
if (std::find(extensionsVector.begin(), extensionsVector.end(), extension) != extensionsVector.end()) {
170+
std::string extension = Filesystem::extension(file).substr(
171+
1); // Remove the leading dot
172+
if (std::find(extensionsVector.begin(), extensionsVector.end(),
173+
extension)
174+
!= extensionsVector.end()) {
170175
int exists = 0;
171-
bool ok = imagecache->get_image_info(ustring(file), 0, 0, uexists, OIIO::TypeInt, &exists);
176+
bool ok = imagecache->get_image_info(ustring(file), 0, 0,
177+
uexists, OIIO::TypeInt,
178+
&exists);
172179
if (ok && exists)
173180
validImages.push_back(file);
174181
}
175182
}
176183

177184
if (validImages.empty()) {
178-
std::cerr << "Error: No valid images found in directory: " << f << "\n";
185+
print(stderr, "Error: No valid images found in directory: {}\n",
186+
f);
179187
} else {
180-
std::sort(validImages.begin(), validImages.end()); // Sort the valid images lexicographically
188+
// Sort the valid images lexicographically
189+
std::sort(validImages.begin(), validImages.end());
181190
for (auto& validImage : validImages) {
182191
mainWin->add_image(validImage);
183192
}
184193
}
185194
} else {
186195
mainWin->add_image(f);
187-
}
196+
}
188197
}
189198

190199
mainWin->current_image(0);
@@ -198,10 +207,8 @@ main(int argc, char* argv[])
198207
#endif
199208
{
200209
size_t mem = Sysutil::memory_used(true);
201-
std::cout << "iv total memory used: " << Strutil::memformat(mem)
202-
<< "\n";
203-
std::cout << "\n";
204-
std::cout << imagecache->getstats(1 + verbose) << "\n";
210+
print("iv total memory used: {}\n\n", Strutil::memformat(mem));
211+
print("{}\n", imagecache->getstats(1 + verbose));
205212
}
206213
shutdown();
207214
return r;

0 commit comments

Comments
 (0)